fix error propagation in export-env (#14847)

- fixes #14801

# Description

- Fixed the issue
- Added some comments mirroring the ones used in `export-env` handling
in `use`
- Added two tests to prevent regressions

# User-Facing Changes

# Tests + Formatting

- 🟢 toolkit fmt
- 🟢 toolkit clippy
- 🟢 toolkit test
- 🟢 toolkit test stdlib

# After Submitting
This commit is contained in:
Bahex 2025-01-16 22:59:39 +03:00 committed by GitHub
parent d66f8cca40
commit 6eff420e17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -57,8 +57,10 @@ impl Command for ExportEnv {
let eval_block = get_eval_block(engine_state);
let _ = eval_block(engine_state, &mut callee_stack, block, input);
// Run the block (discard the result)
let _ = eval_block(engine_state, &mut callee_stack, block, input)?;
// Merge the block's environment to the current stack
redirect_env(engine_state, caller_stack, &callee_stack);
Ok(PipelineData::empty())

View File

@ -187,3 +187,19 @@ fn test_lexical_binding() -> TestResult {
"3",
)
}
#[test]
fn propagate_errors_in_export_env_on_use() -> TestResult {
fail_test(
r#"module foo { export-env { error make -u { msg: "error in export-env"} } }; use foo"#,
"error in export-env",
)
}
#[test]
fn propagate_errors_in_export_env_when_run() -> TestResult {
fail_test(
r#"export-env { error make -u { msg: "error in export-env" } }"#,
"error in export-env",
)
}