mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +02:00
Fix IR for try
(#13811)
# Description Fixes a bug in the IR for `try` to match that of the regular evaluator (continuing from #13515): ```nushell # without IR: try { ^false } catch { 'caught' } # == 'caught' # with IR: try { ^false } catch { 'caught' } # error, non-zero exit code ``` In this PR, both now evaluate to `caught`. For the implementation, I had to add another instruction, and feel free to suggest better alternatives. In the future, it might be possible to get rid of this extra instruction. # User-Facing Changes Bug fix, `try { ^false } catch { 'caught' }` now works in IR.
This commit is contained in:
@ -96,12 +96,12 @@ fn can_catch_infinite_recursion() {
|
||||
|
||||
#[test]
|
||||
fn exit_code_available_in_catch_env() {
|
||||
let actual = nu!("try { nu -c 'exit 42'; null } catch { $env.LAST_EXIT_CODE }");
|
||||
let actual = nu!("try { nu -c 'exit 42' } catch { $env.LAST_EXIT_CODE }");
|
||||
assert_eq!(actual.out, "42");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exit_code_available_in_catch() {
|
||||
let actual = nu!("try { nu -c 'exit 42'; null } catch { |e| $e.exit_code }");
|
||||
let actual = nu!("try { nu -c 'exit 42' } catch { |e| $e.exit_code }");
|
||||
assert_eq!(actual.out, "42");
|
||||
}
|
||||
|
Reference in New Issue
Block a user