handled some unwraps in cd

error reporting now blames the function call span instead of the errored command inside the function
This commit is contained in:
2026-02-19 18:27:51 -05:00
parent bcd0306ad6
commit 1d4c177c64
2 changed files with 11 additions and 3 deletions

View File

@@ -42,8 +42,16 @@ pub fn cd(node: Node, job: &mut JobBldr) -> ShResult<()> {
));
}
env::set_current_dir(new_dir).unwrap();
let new_dir = env::current_dir().unwrap();
if let Err(e) = env::set_current_dir(new_dir) {
return Err(ShErr::full(
ShErrKind::ExecFail,
format!("cd: Failed to change directory: {}", e),
span,
));
}
let new_dir = env::current_dir().map_err(
|e| ShErr::full(ShErrKind::ExecFail, format!("cd: Failed to get current directory: {}", e), span)
)?;
unsafe { env::set_var("PWD", new_dir) };
state::set_status(0);

View File

@@ -319,7 +319,7 @@ impl Dispatcher {
state::set_status(*code);
Ok(())
}
_ => Err(e),
_ => Err(e).blame(blame),
}
} else {
Ok(())