Skip to content

Commit ecba1ec

Browse files
authored
Normalize the path parameter in the generate macro (#988)
1 parent 7ba0f03 commit ecba1ec

File tree

1 file changed

+8
-1
lines changed
  • crates/guest-rust/macro/src

1 file changed

+8
-1
lines changed

crates/guest-rust/macro/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,14 @@ fn parse_source(
155155
let mut files = Vec::new();
156156
let root = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
157157
let mut parse = |path: &Path| -> anyhow::Result<_> {
158-
let (pkg, sources) = resolve.push_path(path)?;
158+
// Try to normalize the path to make the error message more understandable when
159+
// the path is not correct. Fallback to the original path if normalization fails
160+
// (probably return an error somewhere else).
161+
let normalized_path = match std::fs::canonicalize(path) {
162+
Ok(p) => p,
163+
Err(_) => path.to_path_buf(),
164+
};
165+
let (pkg, sources) = resolve.push_path(normalized_path)?;
159166
files.extend(sources);
160167
Ok(pkg)
161168
};

0 commit comments

Comments
 (0)