From 6eff420e1778dddeec8fa9b3f6296c23409ed370 Mon Sep 17 00:00:00 2001 From: Bahex Date: Thu, 16 Jan 2025 22:59:39 +0300 Subject: [PATCH] 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 - :green_circle: toolkit fmt - :green_circle: toolkit clippy - :green_circle: toolkit test - :green_circle: toolkit test stdlib # After Submitting --- crates/nu-command/src/env/export_env.rs | 4 +++- tests/repl/test_modules.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/env/export_env.rs b/crates/nu-command/src/env/export_env.rs index 7c0072b5d4..af7719383a 100644 --- a/crates/nu-command/src/env/export_env.rs +++ b/crates/nu-command/src/env/export_env.rs @@ -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()) diff --git a/tests/repl/test_modules.rs b/tests/repl/test_modules.rs index d088d4ea30..9ededf8f73 100644 --- a/tests/repl/test_modules.rs +++ b/tests/repl/test_modules.rs @@ -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", + ) +}