Generalize nu_protocol::format_shell_error (#15996)

This commit is contained in:
Piepmatz
2025-06-18 22:16:01 +02:00
committed by GitHub
parent f0e90a3733
commit 3f700f03ad
4 changed files with 7 additions and 7 deletions

View File

@ -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))
}

View File

@ -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;

View File

@ -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(),