From 3f700f03ada6bada5c2ac9f67d6b37a1ee3204e6 Mon Sep 17 00:00:00 2001 From: Piepmatz Date: Wed, 18 Jun 2025 22:16:01 +0200 Subject: [PATCH] Generalize `nu_protocol::format_shell_error` (#15996) --- crates/nu-command/src/filesystem/watch.rs | 4 ++-- crates/nu-protocol/src/errors/cli_error.rs | 2 +- crates/nu-protocol/src/errors/mod.rs | 2 +- crates/nu-protocol/src/errors/shell_error/mod.rs | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/nu-command/src/filesystem/watch.rs b/crates/nu-command/src/filesystem/watch.rs index c6cc717fa8..f86c1ec349 100644 --- a/crates/nu-command/src/filesystem/watch.rs +++ b/crates/nu-command/src/filesystem/watch.rs @@ -8,7 +8,7 @@ use notify_debouncer_full::{ use nu_engine::{ClosureEval, command_prelude::*}; use nu_protocol::{ engine::{Closure, StateWorkingSet}, - format_shell_error, + format_cli_error, shell_error::io::IoError, }; use std::{ @@ -208,7 +208,7 @@ impl Command for Watch { } Err(err) => { let working_set = StateWorkingSet::new(engine_state); - eprintln!("{}", format_shell_error(&working_set, &err)); + eprintln!("{}", format_cli_error(&working_set, &err)); } } } diff --git a/crates/nu-protocol/src/errors/cli_error.rs b/crates/nu-protocol/src/errors/cli_error.rs index 06f02cd895..96bb779ebb 100644 --- a/crates/nu-protocol/src/errors/cli_error.rs +++ b/crates/nu-protocol/src/errors/cli_error.rs @@ -63,7 +63,7 @@ fn should_show_warning(engine_state: &EngineState, warning: &ParseWarning) -> bo } } -pub fn format_shell_error(working_set: &StateWorkingSet, error: &ShellError) -> String { +pub fn format_cli_error(working_set: &StateWorkingSet, error: &dyn miette::Diagnostic) -> String { format!("Error: {:?}", CliError(error, working_set)) } diff --git a/crates/nu-protocol/src/errors/mod.rs b/crates/nu-protocol/src/errors/mod.rs index ed5a553287..d453cab3d3 100644 --- a/crates/nu-protocol/src/errors/mod.rs +++ b/crates/nu-protocol/src/errors/mod.rs @@ -8,7 +8,7 @@ mod parse_warning; pub mod shell_error; pub use cli_error::{ - ReportMode, format_shell_error, report_parse_error, report_parse_warning, report_shell_error, + ReportMode, format_cli_error, report_parse_error, report_parse_warning, report_shell_error, report_shell_warning, }; pub use compile_error::CompileError; diff --git a/crates/nu-protocol/src/errors/shell_error/mod.rs b/crates/nu-protocol/src/errors/shell_error/mod.rs index acfd68bce3..488469a725 100644 --- a/crates/nu-protocol/src/errors/shell_error/mod.rs +++ b/crates/nu-protocol/src/errors/shell_error/mod.rs @@ -1,7 +1,7 @@ use super::chained_error::ChainedError; use crate::{ ConfigError, LabeledError, ParseError, Span, Spanned, Type, Value, ast::Operator, - engine::StateWorkingSet, format_shell_error, record, + engine::StateWorkingSet, format_cli_error, record, }; use job::JobError; use miette::Diagnostic; @@ -1418,7 +1418,7 @@ impl ShellError { "msg" => Value::string(self.to_string(), span), "debug" => Value::string(format!("{self:?}"), span), "raw" => Value::error(self.clone(), span), - "rendered" => Value::string(format_shell_error(working_set, &self), span), + "rendered" => Value::string(format_cli_error(working_set, &self), span), "json" => Value::string(serde_json::to_string(&self).expect("Could not serialize error"), span), }; @@ -1431,7 +1431,7 @@ impl ShellError { // TODO: Implement as From trait pub fn wrap(self, working_set: &StateWorkingSet, span: Span) -> ParseError { - let msg = format_shell_error(working_set, &self); + let msg = format_cli_error(working_set, &self); ParseError::LabeledError( msg, "Encountered error during parse-time evaluation".into(),