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", + ) +}