mirror of
https://github.com/nushell/nushell.git
synced 2024-11-24 17:34:00 +01:00
Fix try
: Add set_last_error()
to prepare_error_handler()
for IR eval (#13838)
# Description Fixes a bug with `set_last_error()` introduced by @IanManske not being called during the jump to an error handler in IR eval. Without this, `$env.LAST_EXIT_CODE` wasn't getting set in the `catch` block for an external. # Tests + Formatting Added a `tests/eval` test to cover this in both IR and non-IR eval
This commit is contained in:
parent
5101b5e306
commit
a59477205d
@ -246,6 +246,8 @@ fn prepare_error_handler(
|
||||
) {
|
||||
if let Some(reg_id) = error_handler.error_register {
|
||||
if let Some(error) = error {
|
||||
// Stack state has to be updated for stuff like LAST_EXIT_CODE
|
||||
ctx.stack.set_last_error(&error.item);
|
||||
// Create the error value and put it in the register
|
||||
ctx.put_reg(
|
||||
reg_id,
|
||||
|
@ -451,6 +451,14 @@ fn try_catch_with_non_literal_closure() {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_catch_external() {
|
||||
test_eval(
|
||||
r#"try { nu -c 'exit 1' } catch { $env.LAST_EXIT_CODE }"#,
|
||||
Eq("1"),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn row_condition() {
|
||||
test_eval(
|
||||
|
Loading…
Reference in New Issue
Block a user