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:
@@ -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);
|
||||
|
||||
@@ -319,7 +319,7 @@ impl Dispatcher {
|
||||
state::set_status(*code);
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(e),
|
||||
_ => Err(e).blame(blame),
|
||||
}
|
||||
} else {
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user