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 7a24f91334
commit 18e36622a0
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(); if let Err(e) = env::set_current_dir(new_dir) {
let new_dir = env::current_dir().unwrap(); 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) }; unsafe { env::set_var("PWD", new_dir) };
state::set_status(0); state::set_status(0);

View File

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