Skip to content

Commit 3a85b2b

Browse files
committed
fix(install): replace unwrap() with fallible error handling in native shims
Convert panicking unwrap() calls in write_native_shims() to proper error returns with context messages. Handles edge cases like missing parent directory, incompatible paths, and non-UTF8 paths.
1 parent 3fb6469 commit 3a85b2b

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

crates/vite_install/src/shim.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ pub async fn write_native_shims(
1313
to_bin: impl AsRef<Path>,
1414
) -> Result<(), Error> {
1515
let to_bin = to_bin.as_ref();
16-
let relative_path = diff_paths(source_file, to_bin.parent().unwrap()).unwrap();
17-
let relative_file = relative_path.to_str().unwrap();
16+
let parent = to_bin
17+
.parent()
18+
.ok_or_else(|| Error::CannotFindBinaryPath("shim path has no parent directory".into()))?;
19+
let relative_path = diff_paths(&source_file, parent).ok_or_else(|| {
20+
Error::CannotFindBinaryPath("cannot compute relative path for shim".into())
21+
})?;
22+
let relative_file = relative_path
23+
.to_str()
24+
.ok_or_else(|| Error::CannotFindBinaryPath("shim path is not valid UTF-8".into()))?;
1825

1926
write(to_bin, native_sh_shim(relative_file)).await?;
2027
write(to_bin.with_extension("cmd"), native_cmd_shim(relative_file)).await?;

0 commit comments

Comments
 (0)