Jelajahi Sumber

cli: improve filepath canonicalization error (#1745)

Paul 3 tahun lalu
induk
melakukan
248ef79006
1 mengubah file dengan 12 tambahan dan 3 penghapusan
  1. 12 3
      cli/src/config.rs

+ 12 - 3
cli/src/config.rs

@@ -680,11 +680,20 @@ impl _TestToml {
 /// into a canonical one
 fn canonicalize_filepath_from_origin(
     file_path: impl AsRef<Path>,
-    path: impl AsRef<Path>,
+    origin: impl AsRef<Path>,
 ) -> Result<String> {
     let previous_dir = std::env::current_dir()?;
-    std::env::set_current_dir(path.as_ref().parent().unwrap())?;
-    let result = fs::canonicalize(file_path)?.display().to_string();
+    std::env::set_current_dir(origin.as_ref().parent().unwrap())?;
+    let result = fs::canonicalize(&file_path)
+        .with_context(|| {
+            format!(
+                "Error reading (possibly relative) path: {}. If relative, this is the path that was used as the current path: {}",
+                &file_path.as_ref().display(),
+                &origin.as_ref().display()
+            )
+        })?
+        .display()
+        .to_string();
     std::env::set_current_dir(previous_dir)?;
     Ok(result)
 }