diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index d40acad3c5..80d4973385 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -390,7 +390,7 @@ pub fn evaluate_repl( // Right before we start our prompt and take input from the user, // fire the "pre_prompt" hook if let Some(hook) = config.hooks.pre_prompt.clone() { - if let Err(err) = eval_hook(engine_state, stack, None, vec![], &hook) { + if let Err(err) = eval_hook(engine_state, stack, None, vec![], &hook, "pre_prompt") { report_error_new(engine_state, &err); } } @@ -465,7 +465,9 @@ pub fn evaluate_repl( repl.buffer = s.to_string(); drop(repl); - if let Err(err) = eval_hook(engine_state, stack, None, vec![], &hook) { + if let Err(err) = + eval_hook(engine_state, stack, None, vec![], &hook, "pre_execution") + { report_error_new(engine_state, &err); } } diff --git a/crates/nu-cli/src/util.rs b/crates/nu-cli/src/util.rs index bb36e6bc22..2c41ae60a6 100644 --- a/crates/nu-cli/src/util.rs +++ b/crates/nu-cli/src/util.rs @@ -257,7 +257,14 @@ pub fn eval_source( { result = print_if_stream(stream, stderr_stream, false, exit_code); } else if let Some(hook) = config.hooks.display_output.clone() { - match eval_hook(engine_state, stack, Some(pipeline_data), vec![], &hook) { + match eval_hook( + engine_state, + stack, + Some(pipeline_data), + vec![], + &hook, + "display_output", + ) { Err(err) => { result = Err(err); } diff --git a/crates/nu-command/src/hook.rs b/crates/nu-command/src/hook.rs index 4c82eaa464..fbcdf4a3e1 100644 --- a/crates/nu-command/src/hook.rs +++ b/crates/nu-command/src/hook.rs @@ -33,6 +33,7 @@ pub fn eval_env_change_hook( None, vec![("$before".into(), before), ("$after".into(), after.clone())], hook_value, + "env_change", )?; engine_state @@ -59,6 +60,7 @@ pub fn eval_hook( input: Option<PipelineData>, arguments: Vec<(String, Value)>, value: &Value, + hook_name: &str, ) -> Result<PipelineData, ShellError> { let value_span = value.span(); @@ -96,11 +98,15 @@ pub fn eval_hook( Type::Any, false, ); - vars.push((var_id, val)); } - let output = parse(&mut working_set, Some("hook"), val.as_bytes(), false); + let output = parse( + &mut working_set, + Some(&format!("{hook_name} hook")), + val.as_bytes(), + false, + ); if let Some(err) = working_set.parse_errors.first() { report_error(&working_set, err); @@ -144,7 +150,14 @@ pub fn eval_hook( } Value::List { vals, .. } => { for val in vals { - eval_hook(engine_state, stack, None, arguments.clone(), val)?; + eval_hook( + engine_state, + stack, + None, + arguments.clone(), + val, + &format!("{hook_name} list, recursive"), + )?; } } Value::Record { .. } => { @@ -218,12 +231,15 @@ pub fn eval_hook( Type::Any, false, ); - vars.push((var_id, val)); } - let output = - parse(&mut working_set, Some("hook"), val.as_bytes(), false); + let output = parse( + &mut working_set, + Some(&format!("{hook_name} hook")), + val.as_bytes(), + false, + ); if let Some(err) = working_set.parse_errors.first() { report_error(&working_set, err); diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index 0aa0453032..2082e28775 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -371,6 +371,7 @@ impl ExternalCommand { ), )], &hook, + "command_not_found", ) { err_str = format!("{}\n{}", err_str, val); diff --git a/src/test_bins.rs b/src/test_bins.rs index 93a5b809eb..2bb12eaa80 100644 --- a/src/test_bins.rs +++ b/src/test_bins.rs @@ -213,7 +213,14 @@ pub fn nu_repl() { // Check for pre_prompt hook let config = engine_state.get_config(); if let Some(hook) = config.hooks.pre_prompt.clone() { - if let Err(err) = eval_hook(&mut engine_state, &mut stack, None, vec![], &hook) { + if let Err(err) = eval_hook( + &mut engine_state, + &mut stack, + None, + vec![], + &hook, + "pre_prompt", + ) { outcome_err(&engine_state, &err); } } @@ -238,7 +245,14 @@ pub fn nu_repl() { .buffer = line.to_string(); if let Some(hook) = config.hooks.pre_execution.clone() { - if let Err(err) = eval_hook(&mut engine_state, &mut stack, None, vec![], &hook) { + if let Err(err) = eval_hook( + &mut engine_state, + &mut stack, + None, + vec![], + &hook, + "pre_execution", + ) { outcome_err(&engine_state, &err); } }