This is an automated email from the ASF dual-hosted git repository.

Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 78f6cf6892 docs(bindings/nodejs): clarify errors in conditional stat 
and delete options (#9374)
78f6cf6892 is described below

commit 78f6cf689294caf951f21200a96ee5445d9dfc3d
Author: Xuanwo <[email protected]>
AuthorDate: Sun Nov 29 19:31:13 2026 +0800

    docs(bindings/nodejs): clarify errors in conditional stat and delete 
options (#9374)
    
    docs(bindings/nodejs): clarify conditional option errors
    
    Describe conditional option failures using the JavaScript error message and 
keep the specification link in generated docs.
    
    Refs #9334
---
 bindings/nodejs/generated.d.ts        |  42 ++++++-------
 bindings/nodejs/src/options/delete.rs |   8 +--
 bindings/nodejs/src/options/stat.rs   |  34 +++++-----
 dev/src/generate/nodejs.rs            | 115 +++++++++++++++++++++-------------
 4 files changed, 113 insertions(+), 86 deletions(-)

diff --git a/bindings/nodejs/generated.d.ts b/bindings/nodejs/generated.d.ts
index 6fe680e8e2..ccc2817801 100644
--- a/bindings/nodejs/generated.d.ts
+++ b/bindings/nodejs/generated.d.ts
@@ -1210,18 +1210,18 @@ export declare class Writer {
  * every condition must hold for the delete to proceed:
  *
  * - A false condition fails the delete with
- * `crate::ErrorKind::ConditionNotMatch`.
+ * an error whose message includes `ConditionNotMatch`.
  * - A condition the service does not advertise through its capability fails
  * the delete with an error whose message includes `Unsupported`; OpenDAL never
  * silently drops a condition. A service that cannot preserve a
  * combination of conditions also returns `Unsupported`.
  * - A service-side conflict unrelated to these conditions surfaces as
- * `crate::ErrorKind::Conflict`.
+ * an error whose message includes `Conflict`.
  *
  * With valid, supported options, deleting a missing file remains a
  * successful no-op once every condition holds.
  *
- * See the conditional operation specification
+ * See the [conditional operation 
specification](https://opendal.apache.org/docs/specifications/conditional-operations/)
  * for the complete cross-operation contract.
  */
 export interface DeleteOptions {
@@ -1254,7 +1254,7 @@ export interface DeleteOptions {
    *
    * The condition succeeds when the file exists and its ETag equals this
    * value. A file with a different ETag, or a missing file, fails the
-   * delete with `crate::ErrorKind::ConditionNotMatch`. Only concrete
+   * delete with an error whose message includes `ConditionNotMatch`. Only 
concrete
    * ETag values are portable; a wildcard such as `"*"` has no portable
    * meaning here.
    *
@@ -1461,14 +1461,14 @@ export interface ReadOptions {
  *
  * Each condition checks the file being observed, and every condition must
  * hold for the stat to return metadata. With valid, supported options, stat
- * returns `crate::ErrorKind::NotFound` for a missing file. An existing
- * file that fails a condition returns
- * `crate::ErrorKind::ConditionNotMatch`, and a condition the service does
+ * produces an error whose message includes `NotFound` for a missing file. An 
existing
+ * file that fails a condition produces
+ * an error whose message includes `ConditionNotMatch`, and a condition the 
service does
  * not advertise through its capability returns
  * an error whose message includes `Unsupported`; OpenDAL never silently drops 
a
  * condition.
  *
- * See the conditional operation specification
+ * See the [conditional operation 
specification](https://opendal.apache.org/docs/specifications/conditional-operations/)
  * for the complete cross-operation contract.
  */
 export interface StatOptions {
@@ -1476,8 +1476,8 @@ export interface StatOptions {
    * Stat the given version of the file instead of the current one.
    *
    * This selects which stored version the stat describes; it is not a
-   * condition on the file. A version that does not exist returns
-   * `crate::ErrorKind::NotFound`.
+   * condition on the file. A version that does not exist produces
+   * an error whose message includes `NotFound`.
    *
    * Check `Capability.statWithVersion` before using this
    * option.
@@ -1487,9 +1487,9 @@ export interface StatOptions {
    * Stat only when the file has this exact ETag.
    *
    * The condition succeeds when the file exists and its ETag equals this
-   * value. A file with a different ETag returns
-   * `crate::ErrorKind::ConditionNotMatch`; a missing file returns
-   * `crate::ErrorKind::NotFound`. Only concrete ETag values are
+   * value. A file with a different ETag produces
+   * an error whose message includes `ConditionNotMatch`; a missing file 
produces
+   * an error whose message includes `NotFound`. Only concrete ETag values are
    * portable; a wildcard such as `"*"` has no portable meaning here.
    *
    * The operation returns an error whose message includes `Unsupported` when 
the
@@ -1501,8 +1501,8 @@ export interface StatOptions {
    *
    * With a concrete ETag value, the condition succeeds when the file
    * exists with a different ETag. A file whose ETag equals this value
-   * returns `crate::ErrorKind::ConditionNotMatch`; a missing file
-   * returns `crate::ErrorKind::NotFound`. Only concrete ETag values
+   * produces an error whose message includes `ConditionNotMatch`; a missing 
file
+   * produces an error whose message includes `NotFound`. Only concrete ETag 
values
    * are portable; a wildcard such as `"*"` has no portable meaning here.
    *
    * The operation returns an error whose message includes `Unsupported` when 
the
@@ -1514,9 +1514,9 @@ export interface StatOptions {
    * Stat only when the file was modified after this timestamp.
    *
    * The condition succeeds when the file exists and was modified after
-   * this time. A file not modified since this time returns
-   * `crate::ErrorKind::ConditionNotMatch`; a missing file returns
-   * `crate::ErrorKind::NotFound`.
+   * this time. A file not modified since this time produces
+   * an error whose message includes `ConditionNotMatch`; a missing file 
produces
+   * an error whose message includes `NotFound`.
    *
    * The operation returns an error whose message includes `Unsupported` when 
the
    * service does not advertise
@@ -1531,9 +1531,9 @@ export interface StatOptions {
    * Stat only when the file was not modified after this timestamp.
    *
    * The condition succeeds when the file exists and was not modified
-   * after this time. A file modified after this time returns
-   * `crate::ErrorKind::ConditionNotMatch`; a missing file returns
-   * `crate::ErrorKind::NotFound`.
+   * after this time. A file modified after this time produces
+   * an error whose message includes `ConditionNotMatch`; a missing file 
produces
+   * an error whose message includes `NotFound`.
    *
    * The operation returns an error whose message includes `Unsupported` when 
the
    * service does not advertise
diff --git a/bindings/nodejs/src/options/delete.rs 
b/bindings/nodejs/src/options/delete.rs
index 2de9c3b89b..1f6ef445d7 100644
--- a/bindings/nodejs/src/options/delete.rs
+++ b/bindings/nodejs/src/options/delete.rs
@@ -23,18 +23,18 @@
 /// every condition must hold for the delete to proceed:
 ///
 /// - A false condition fails the delete with
-/// `crate::ErrorKind::ConditionNotMatch`.
+/// an error whose message includes `ConditionNotMatch`.
 /// - A condition the service does not advertise through its capability fails
 /// the delete with an error whose message includes `Unsupported`; OpenDAL 
never
 /// silently drops a condition. A service that cannot preserve a
 /// combination of conditions also returns `Unsupported`.
 /// - A service-side conflict unrelated to these conditions surfaces as
-/// `crate::ErrorKind::Conflict`.
+/// an error whose message includes `Conflict`.
 ///
 /// With valid, supported options, deleting a missing file remains a
 /// successful no-op once every condition holds.
 ///
-/// See the conditional operation specification
+/// See the [conditional operation 
specification](https://opendal.apache.org/docs/specifications/conditional-operations/)
 /// for the complete cross-operation contract.
 #[napi(object)]
 #[derive(Debug, Default)]
@@ -65,7 +65,7 @@ pub struct DeleteOptions {
     ///
     /// The condition succeeds when the file exists and its ETag equals this
     /// value. A file with a different ETag, or a missing file, fails the
-    /// delete with `crate::ErrorKind::ConditionNotMatch`. Only concrete
+    /// delete with an error whose message includes `ConditionNotMatch`. Only 
concrete
     /// ETag values are portable; a wildcard such as `"*"` has no portable
     /// meaning here.
     ///
diff --git a/bindings/nodejs/src/options/stat.rs 
b/bindings/nodejs/src/options/stat.rs
index 55a8724250..d8357f89db 100644
--- a/bindings/nodejs/src/options/stat.rs
+++ b/bindings/nodejs/src/options/stat.rs
@@ -21,14 +21,14 @@
 ///
 /// Each condition checks the file being observed, and every condition must
 /// hold for the stat to return metadata. With valid, supported options, stat
-/// returns `crate::ErrorKind::NotFound` for a missing file. An existing
-/// file that fails a condition returns
-/// `crate::ErrorKind::ConditionNotMatch`, and a condition the service does
+/// produces an error whose message includes `NotFound` for a missing file. An 
existing
+/// file that fails a condition produces
+/// an error whose message includes `ConditionNotMatch`, and a condition the 
service does
 /// not advertise through its capability returns
 /// an error whose message includes `Unsupported`; OpenDAL never silently 
drops a
 /// condition.
 ///
-/// See the conditional operation specification
+/// See the [conditional operation 
specification](https://opendal.apache.org/docs/specifications/conditional-operations/)
 /// for the complete cross-operation contract.
 #[napi(object)]
 #[derive(Debug, Default)]
@@ -36,8 +36,8 @@ pub struct StatOptions {
     /// Stat the given version of the file instead of the current one.
     ///
     /// This selects which stored version the stat describes; it is not a
-    /// condition on the file. A version that does not exist returns
-    /// `crate::ErrorKind::NotFound`.
+    /// condition on the file. A version that does not exist produces
+    /// an error whose message includes `NotFound`.
     ///
     /// Check `Capability.statWithVersion` before using this
     /// option.
@@ -46,9 +46,9 @@ pub struct StatOptions {
     /// Stat only when the file has this exact ETag.
     ///
     /// The condition succeeds when the file exists and its ETag equals this
-    /// value. A file with a different ETag returns
-    /// `crate::ErrorKind::ConditionNotMatch`; a missing file returns
-    /// `crate::ErrorKind::NotFound`. Only concrete ETag values are
+    /// value. A file with a different ETag produces
+    /// an error whose message includes `ConditionNotMatch`; a missing file 
produces
+    /// an error whose message includes `NotFound`. Only concrete ETag values 
are
     /// portable; a wildcard such as `"*"` has no portable meaning here.
     ///
     /// The operation returns an error whose message includes `Unsupported` 
when the
@@ -59,8 +59,8 @@ pub struct StatOptions {
     ///
     /// With a concrete ETag value, the condition succeeds when the file
     /// exists with a different ETag. A file whose ETag equals this value
-    /// returns `crate::ErrorKind::ConditionNotMatch`; a missing file
-    /// returns `crate::ErrorKind::NotFound`. Only concrete ETag values
+    /// produces an error whose message includes `ConditionNotMatch`; a 
missing file
+    /// produces an error whose message includes `NotFound`. Only concrete 
ETag values
     /// are portable; a wildcard such as `"*"` has no portable meaning here.
     ///
     /// The operation returns an error whose message includes `Unsupported` 
when the
@@ -71,9 +71,9 @@ pub struct StatOptions {
     /// Stat only when the file was modified after this timestamp.
     ///
     /// The condition succeeds when the file exists and was modified after
-    /// this time. A file not modified since this time returns
-    /// `crate::ErrorKind::ConditionNotMatch`; a missing file returns
-    /// `crate::ErrorKind::NotFound`.
+    /// this time. A file not modified since this time produces
+    /// an error whose message includes `ConditionNotMatch`; a missing file 
produces
+    /// an error whose message includes `NotFound`.
     ///
     /// The operation returns an error whose message includes `Unsupported` 
when the
     /// service does not advertise
@@ -87,9 +87,9 @@ pub struct StatOptions {
     /// Stat only when the file was not modified after this timestamp.
     ///
     /// The condition succeeds when the file exists and was not modified
-    /// after this time. A file modified after this time returns
-    /// `crate::ErrorKind::ConditionNotMatch`; a missing file returns
-    /// `crate::ErrorKind::NotFound`.
+    /// after this time. A file modified after this time produces
+    /// an error whose message includes `ConditionNotMatch`; a missing file 
produces
+    /// an error whose message includes `NotFound`.
     ///
     /// The operation returns an error whose message includes `Unsupported` 
when the
     /// service does not advertise
diff --git a/dev/src/generate/nodejs.rs b/dev/src/generate/nodejs.rs
index c0f585e77a..4bbaf284f1 100644
--- a/dev/src/generate/nodejs.rs
+++ b/dev/src/generate/nodejs.rs
@@ -385,33 +385,45 @@ fn js_type(struct_name: &str, field: &OptionField) -> 
Result<JsType> {
 /// The core doc comment as it reads in JS. napi-rs copies it into
 /// `generated.d.ts`.
 ///
-/// Rustdoc links become plain code spans, because JS documentation cannot
-/// resolve Rust paths: 
``[`Capability::list_with_limit`](crate::Capability::list_with_limit)``
-/// and ``[`crate::layers::SimulateLayer`]`` keep only their code span, and
-/// `[conditional operation 
specification][crate::docs::specs::conditional_operations]`
-/// keeps only its text. Code spans that name a JS property then use its JS
-/// name (see [`js_code_span`]); other code spans stay as written.
+/// Rustdoc links to code become plain code spans. Reference links to the
+/// conditional operations specification point to its website page. Other
+/// crate reference links keep their label.
 ///
-/// JS errors carry no `ErrorKind`, so `crate::ErrorKind::Unsupported` reads
-/// "an error whose message includes `Unsupported`".
+/// Code spans that name a JS property use its JS name (see [`js_code_span`]).
+/// OpenDAL error kinds appear in the JS error message.
 fn js_doc(lines: &[String], options: &JsOptions, capabilities: 
&[CapabilityField]) -> Vec<String> {
-    lines
-        .iter()
-        .map(|line| {
-            rewrite_code_spans(&strip_crate_reference_links(line), |code| {
-                js_code_span(code, options, capabilities)
-            })
+    let mut doc = String::new();
+    for line in lines {
+        let line = rewrite_code_spans(&render_crate_reference_links(line), 
|code| {
+            js_code_span(code, options, capabilities)
+        });
+        doc.push_str(&line.replace(
+            "`crate::ErrorKind::Unsupported`",
+            "an error whose message includes `Unsupported`",
+        ));
+        doc.push('\n');
+    }
+
+    for kind in ["NotFound", "ConditionNotMatch", "Conflict"] {
+        let reference = format!("`crate::ErrorKind::{kind}`");
+        let error = format!("an error whose message includes `{kind}`");
+        doc = doc
             .replace(
-                "`crate::ErrorKind::Unsupported`",
-                "an error whose message includes `Unsupported`",
+                &format!("returns {reference}"),
+                &format!("produces {error}"),
             )
-        })
-        .collect()
+            .replace(
+                &format!("returns\n{reference}"),
+                &format!("produces\n{error}"),
+            )
+            .replace(&reference, &error);
+    }
+    doc.split_terminator('\n').map(str::to_owned).collect()
 }
 
-/// Replace each reference-style rustdoc link to a crate item,
-/// `[text][crate::path]`, with its text.
-fn strip_crate_reference_links(line: &str) -> String {
+/// Render the known specification link and keep only the label of other
+/// reference-style links to crate items.
+fn render_crate_reference_links(line: &str) -> String {
     let mut out = String::with_capacity(line.len());
     let mut rest = line;
     while let Some(pos) = rest.find("][crate::") {
@@ -420,7 +432,14 @@ fn strip_crate_reference_links(line: &str) -> String {
             break;
         };
         out.push_str(&rest[..open]);
-        out.push_str(&rest[open + 1..pos]);
+        if &target[..close] == "crate::docs::specs::conditional_operations" {
+            out.push_str(&rest[open..=pos]);
+            out.push_str(
+                
"(https://opendal.apache.org/docs/specifications/conditional-operations/)",
+            );
+        } else {
+            out.push_str(&rest[open + 1..pos]);
+        }
         rest = &target[close + 1..];
     }
     out.push_str(rest);
@@ -790,11 +809,11 @@ mod tests {
     }
 
     #[test]
-    fn test_js_doc_strips_rustdoc_links() {
+    fn test_js_doc_renders_rustdoc_links() {
         let lines = [
             "Rely on 
[`crate::layers::SimulateLayer`](crate::layers::SimulateLayer) and 
[`Self::recursive`].",
             "A [plain](https://opendal.apache.org) link and `code` stay.",
-            "See the [conditional operation 
specification][crate::docs::specs::conditional_operations]",
+            "Read the [operation 
contract][crate::docs::specs::conditional_operations].",
             "and 
[`Capability::list_with_limit`][crate::Capability::list_with_limit]; [a][b] 
stays.",
         ]
         .map(String::from);
@@ -803,7 +822,7 @@ mod tests {
             [
                 "Rely on `crate::layers::SimulateLayer` and 
`Self::recursive`.",
                 "A [plain](https://opendal.apache.org) link and `code` stay.",
-                "See the conditional operation specification",
+                "Read the [operation 
contract](https://opendal.apache.org/docs/specifications/conditional-operations/).",
                 "and `Capability.listWithLimit`; [a][b] stays.",
             ]
         );
@@ -837,24 +856,26 @@ mod tests {
     }
 
     #[test]
-    fn test_js_doc_describes_unsupported_errors_by_message() {
+    fn test_js_doc_describes_errors_by_message() {
         let lines = [
             "Fails with [`crate::ErrorKind::Unsupported`] when unsupported.",
             "The operation returns [`crate::ErrorKind::Unsupported`] when the",
-            "A missing file returns [`crate::ErrorKind::NotFound`], a failed 
condition",
-            "[`crate::ErrorKind::ConditionNotMatch`], and some calls also 
return `Unsupported`.",
+            "A missing file returns [`crate::ErrorKind::NotFound`]. A failed 
condition returns",
+            "[`crate::ErrorKind::ConditionNotMatch`]. Some calls also return 
`Unsupported`.",
+            "A service conflict surfaces as [`crate::ErrorKind::Conflict`].",
+            "An unrelated `crate::ErrorKind::PermissionDenied` stays.",
         ]
         .map(String::from);
-        // The rewrite applies to every options struct, not only `ListOptions`,
-        // and leaves other error kinds as written.
         for options in [&LIST_OPTIONS, &STAT_OPTIONS, &DELETE_OPTIONS] {
             assert_eq!(
                 js_doc(&lines, options, &core_capabilities()),
                 [
                     "Fails with an error whose message includes `Unsupported` 
when unsupported.",
                     "The operation returns an error whose message includes 
`Unsupported` when the",
-                    "A missing file returns `crate::ErrorKind::NotFound`, a 
failed condition",
-                    "`crate::ErrorKind::ConditionNotMatch`, and some calls 
also return `Unsupported`.",
+                    "A missing file produces an error whose message includes 
`NotFound`. A failed condition produces",
+                    "an error whose message includes `ConditionNotMatch`. Some 
calls also return `Unsupported`.",
+                    "A service conflict surfaces as an error whose message 
includes `Conflict`.",
+                    "An unrelated `crate::ErrorKind::PermissionDenied` stays.",
                 ],
                 "{}",
                 options.name
@@ -863,7 +884,7 @@ mod tests {
     }
 
     #[test]
-    fn test_options_docs_describe_unsupported_errors_by_message() {
+    fn test_options_docs_describe_errors_by_message() {
         // Core's struct and field docs, as rendered for JS, for each struct.
         for (options, expected) in [
             (
@@ -877,6 +898,12 @@ mod tests {
             (
                 &STAT_OPTIONS,
                 &[
+                    "/// produces an error whose message includes `NotFound` 
for a missing file.",
+                    "/// an error whose message includes `ConditionNotMatch`, 
and a condition the service does\n",
+                    concat!(
+                        "    /// an error whose message includes 
`ConditionNotMatch`; a missing file produces\n",
+                        "    /// an error whose message includes `NotFound`. 
Only concrete ETag values are\n",
+                    ),
                     concat!(
                         "/// not advertise through its capability returns\n",
                         "/// an error whose message includes `Unsupported`; 
OpenDAL never silently drops a\n",
@@ -896,6 +923,9 @@ mod tests {
             (
                 &DELETE_OPTIONS,
                 &[
+                    "/// an error whose message includes `Conflict`.\n",
+                    "/// combination of conditions also returns 
`Unsupported`.\n",
+                    "    /// delete with an error whose message includes 
`ConditionNotMatch`. Only concrete\n",
                     concat!(
                         "/// - A condition the service does not advertise 
through its capability fails\n",
                         "/// the delete with an error whose message includes 
`Unsupported`; OpenDAL never\n",
@@ -914,18 +944,10 @@ mod tests {
                 assert!(rendered.contains(expected), "{name}: {expected}");
             }
             assert!(
-                !rendered.contains("ErrorKind::Unsupported"),
+                !rendered.contains("crate::ErrorKind::"),
                 "{name}: {rendered}"
             );
         }
-
-        // Other error kinds stay as core writes them.
-        let stat = render(core_options("StatOptions"), &STAT_OPTIONS).unwrap();
-        assert!(stat.contains(
-            "/// `crate::ErrorKind::ConditionNotMatch`, and a condition the 
service does\n"
-        ));
-        let delete = render(core_options("DeleteOptions"), 
&DELETE_OPTIONS).unwrap();
-        assert!(delete.contains("/// `crate::ErrorKind::Conflict`.\n"));
     }
 
     #[test]
@@ -948,6 +970,7 @@ mod tests {
 
     #[test]
     fn test_options_docs_use_js_capability_names() {
+        let specification_link = "[conditional operation 
specification](https://opendal.apache.org/docs/specifications/conditional-operations/)";
         // Core links each version or condition option to the capability that
         // it requires.
         for (options, expected) in [
@@ -977,13 +1000,17 @@ mod tests {
                 let doc = field_doc(&rendered, name).join(" ");
                 assert!(doc.contains(capability), "{name}: {doc}");
             }
-            // No Rust capability paths or rustdoc link syntax reach JS.
+            assert!(rendered.contains(&format!("/// See the 
{specification_link}\n")));
+            // Rust capability paths and rustdoc link syntax stay out of the 
generated docs.
             for line in rendered
                 .lines()
                 .filter(|l| l.trim_start().starts_with("///"))
             {
                 assert!(!line.contains("Capability::"), "{line}");
-                assert!(!line.contains('['), "{line}");
+                assert!(
+                    !line.replace(specification_link, "").contains('['),
+                    "{line}"
+                );
             }
         }
     }

Reply via email to