mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 15:11:52 +02:00
Make exit code available in catch
block (#12648)
# Description Bandaid fix for #12643, where it is not possible to get the exit code of a failed external command while also having the external command inherit nushell's stdout and stderr. This changes `try` so that the exit code of external command is available in the `catch` block via the usual `$env.LAST_EXIT_CODE`. # Tests + Formatting Added one test. # After Submitting Rework I/O redirection and possibly exit codes.
This commit is contained in:
@ -93,3 +93,9 @@ fn can_catch_infinite_recursion() {
|
||||
"#);
|
||||
assert_eq!(actual.out, "Caught infinite recursion");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exit_code_available_in_catch() {
|
||||
let actual = nu!("try { nu -c 'exit 42' } catch { $env.LAST_EXIT_CODE }");
|
||||
assert_eq!(actual.out, "42");
|
||||
}
|
||||
|
Reference in New Issue
Block a user