You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2026/10/26 19:11:07 UTC

(opendal-yinyang) branch xuanwo/managed-sync-cli updated: fix: adapt the replica error type at the CLI boundary

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

Xuanwo pushed a commit to branch xuanwo/managed-sync-cli
in repository https://gitbox.apache.org/repos/asf/opendal-yinyang.git


The following commit(s) were added to refs/heads/xuanwo/managed-sync-cli by this push:
     new b25f625  fix: adapt the replica error type at the CLI boundary
b25f625 is described below

commit b25f6254d019c5e460b492adf7a47d89d5450533
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Tue Oct 27 03:11:01 2026 +0800

    fix: adapt the replica error type at the CLI boundary
    
    The replica layer returns `Box<dyn Error + Send + Sync>`; convert it to
    the adapter's error type while keeping the diagnostic text, which names
    the offending path (for example a missing bound root).
    
    Co-authored-by: Chojan Shang <ps...@apache.org>
---
 src/sync_cli.rs | 42 ++++++++++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 12 deletions(-)

diff --git a/src/sync_cli.rs b/src/sync_cli.rs
index f80528f..acbcbb4 100644
--- a/src/sync_cli.rs
+++ b/src/sync_cli.rs
@@ -444,13 +444,17 @@ async fn status(
 ) -> Result<ExitCode, Box<dyn std::error::Error>> {
     // Classify the local binding without touching the authority, so an unbound
     // or invalid binding stays offline and never blocks on remote I/O.
-    let local = DirectorySync::inspect_local(&config.staging, None).await?;
+    let local = DirectorySync::inspect_local(&config.staging, None)
+        .await
+        .map_err(fatal)?;
     let inspection = match local.binding.state {
         domain::BindingState::Bound => match connect(config, operator).await {
-            Ok(authority) => DirectorySync::inspect(authority, &config.staging).await?,
-            Err(error) => {
-                DirectorySync::inspect_local(&config.staging, Some(error.to_string())).await?
-            }
+            Ok(authority) => DirectorySync::inspect(authority, &config.staging)
+                .await
+                .map_err(fatal)?,
+            Err(error) => DirectorySync::inspect_local(&config.staging, Some(error.to_string()))
+                .await
+                .map_err(fatal)?,
         },
         _ => local,
     };
@@ -469,7 +473,9 @@ async fn init(
     directory: &Path,
 ) -> Result<ExitCode, Box<dyn std::error::Error>> {
     let authority = connect(config, operator).await?;
-    DirectorySync::init(authority, &config.staging, directory).await?;
+    DirectorySync::init(authority, &config.staging, directory)
+        .await
+        .map_err(fatal)?;
     println!(
         "sync bound {} to state {}",
         directory.display(),
@@ -483,8 +489,10 @@ async fn reconcile(
     operator: opendal::Operator,
 ) -> Result<ExitCode, Box<dyn std::error::Error>> {
     let authority = connect(config, operator).await?;
-    let mut directory = DirectorySync::open(authority, &config.staging).await?;
-    let outcome = directory.run().await?;
+    let mut directory = DirectorySync::open(authority, &config.staging)
+        .await
+        .map_err(fatal)?;
+    let outcome = directory.run().await.map_err(fatal)?;
     report(&outcome)?;
     Ok(ExitCode::SUCCESS)
 }
@@ -508,7 +516,9 @@ async fn export(
         }
     };
     let authority = connect(config, operator).await?;
-    let directory = DirectorySync::open(authority, &config.staging).await?;
+    let directory = DirectorySync::open(authority, &config.staging)
+        .await
+        .map_err(fatal)?;
     let mut file = std::fs::File::create(output)
         .map_err(|error| format!("create export {}: {error}", output.display()))?;
     let result: Result<(), Box<dyn std::error::Error + Send + Sync>> = if let Some(id) = &artifact {
@@ -526,7 +536,7 @@ async fn export(
     if let Err(error) = result {
         // A failed export must not leave a pseudo artifact behind.
         let _ = std::fs::remove_file(output);
-        return Err(error);
+        return Err(fatal(error));
     }
     Ok(ExitCode::SUCCESS)
 }
@@ -554,8 +564,10 @@ async fn resolve(
         }
     };
     let authority = connect(config, operator).await?;
-    let mut directory = DirectorySync::open(authority, &config.staging).await?;
-    let outcome = directory.resolve(conflict, decision).await?;
+    let mut directory = DirectorySync::open(authority, &config.staging)
+        .await
+        .map_err(fatal)?;
+    let outcome = directory.resolve(conflict, decision).await.map_err(fatal)?;
     report(&outcome)?;
     Ok(ExitCode::SUCCESS)
 }
@@ -587,6 +599,12 @@ fn hex(bytes: &[u8]) -> String {
     bytes.iter().map(|byte| format!("{byte:02x}")).collect()
 }
 
+/// Adapts the replica layer's boxed error to this adapter's error type while
+/// keeping the diagnostic text, which names the offending path.
+fn fatal(error: Box<dyn std::error::Error + Send + Sync>) -> Box<dyn std::error::Error> {
+    error.to_string().into()
+}
+
 fn project(inspection: &domain::Inspection) -> Result<SyncStatus, String> {
     let entries = inspection
         .entries