mirror of
https://github.com/nushell/nushell.git
synced 2025-05-30 06:39:33 +02:00
Error printing changes for watch
(#5389)
* Move CliError to nu-protocol clean up comment * Enable printing errors instead of just returning them * Nicer Miette error printing in watch command
This commit is contained in:
parent
7a7aa310aa
commit
5077242892
@ -1,7 +1,6 @@
|
|||||||
mod commands;
|
mod commands;
|
||||||
mod completions;
|
mod completions;
|
||||||
mod config_files;
|
mod config_files;
|
||||||
mod errors;
|
|
||||||
mod eval_file;
|
mod eval_file;
|
||||||
mod menus;
|
mod menus;
|
||||||
mod nu_highlight;
|
mod nu_highlight;
|
||||||
@ -17,7 +16,6 @@ mod validation;
|
|||||||
pub use commands::evaluate_commands;
|
pub use commands::evaluate_commands;
|
||||||
pub use completions::{FileCompletion, NuCompleter};
|
pub use completions::{FileCompletion, NuCompleter};
|
||||||
pub use config_files::eval_config_contents;
|
pub use config_files::eval_config_contents;
|
||||||
pub use errors::CliError;
|
|
||||||
pub use eval_file::evaluate_file;
|
pub use eval_file::evaluate_file;
|
||||||
pub use menus::{DescriptionMenu, NuHelpCompleter};
|
pub use menus::{DescriptionMenu, NuHelpCompleter};
|
||||||
pub use nu_highlight::NuHighlight;
|
pub use nu_highlight::NuHighlight;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::CliError;
|
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use nu_engine::eval_block;
|
use nu_engine::eval_block;
|
||||||
use nu_parser::{escape_quote_string, lex, parse, unescape_unquote_string, Token, TokenContents};
|
use nu_parser::{escape_quote_string, lex, parse, unescape_unquote_string, Token, TokenContents};
|
||||||
use nu_protocol::engine::StateWorkingSet;
|
use nu_protocol::engine::StateWorkingSet;
|
||||||
|
use nu_protocol::CliError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{EngineState, Stack},
|
engine::{EngineState, Stack},
|
||||||
PipelineData, ShellError, Span, Value,
|
PipelineData, ShellError, Span, Value,
|
||||||
|
@ -6,10 +6,10 @@ use std::time::Duration;
|
|||||||
use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher};
|
use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher};
|
||||||
use nu_engine::{current_dir, eval_block, CallExt};
|
use nu_engine::{current_dir, eval_block, CallExt};
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack, StateWorkingSet};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Spanned, SyntaxShape,
|
format_error, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature,
|
||||||
Value,
|
Spanned, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
// durations chosen mostly arbitrarily
|
// durations chosen mostly arbitrarily
|
||||||
@ -219,9 +219,8 @@ impl Command for Watch {
|
|||||||
val.print(engine_state, stack)?;
|
val.print(engine_state, stack)?;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// TODO: this isn't as nice as the Miette errors. Find a way to print those.
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
// Unfortunately can't just wrap err in PipelineData, PipelineData.print() doesn't work that way
|
eprintln!("{}", format_error(&working_set, &err));
|
||||||
eprintln!("{err:?}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ use nu_color_config::{get_color_config, style_primitive};
|
|||||||
use nu_engine::column::get_columns;
|
use nu_engine::column::get_columns;
|
||||||
use nu_engine::{env_to_string, CallExt};
|
use nu_engine::{env_to_string, CallExt};
|
||||||
use nu_protocol::ast::{Call, PathMember};
|
use nu_protocol::ast::{Call, PathMember};
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack, StateWorkingSet};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, Config, DataSource, Example, IntoPipelineData, ListStream, PipelineData,
|
format_error, Category, Config, DataSource, Example, IntoPipelineData, ListStream,
|
||||||
PipelineMetadata, RawStream, ShellError, Signature, Span, SyntaxShape, Value,
|
PipelineData, PipelineMetadata, RawStream, ShellError, Signature, Span, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
use nu_table::{StyledString, TextStyle, Theme};
|
use nu_table::{StyledString, TextStyle, Theme};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
@ -141,7 +141,14 @@ impl Command for Table {
|
|||||||
}
|
}
|
||||||
.into_pipeline_data())
|
.into_pipeline_data())
|
||||||
}
|
}
|
||||||
PipelineData::Value(Value::Error { error }, ..) => Err(error),
|
PipelineData::Value(Value::Error { error }, ..) => {
|
||||||
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
|
Ok(Value::String {
|
||||||
|
val: format_error(&working_set, &error),
|
||||||
|
span: call.head,
|
||||||
|
}
|
||||||
|
.into_pipeline_data())
|
||||||
|
}
|
||||||
PipelineData::Value(Value::CustomValue { val, span }, ..) => {
|
PipelineData::Value(Value::CustomValue { val, span }, ..) => {
|
||||||
let base_pipeline = val.to_base_value(span)?.into_pipeline_data();
|
let base_pipeline = val.to_base_value(span)?.into_pipeline_data();
|
||||||
self.run(engine_state, stack, call, base_pipeline)
|
self.run(engine_state, stack, call, base_pipeline)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
use crate::engine::StateWorkingSet;
|
||||||
use miette::{LabeledSpan, MietteHandler, ReportHandler, Severity, SourceCode};
|
use miette::{LabeledSpan, MietteHandler, ReportHandler, Severity, SourceCode};
|
||||||
use nu_protocol::engine::StateWorkingSet;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
/// This error exists so that we can defer SourceCode handling. It simply
|
/// This error exists so that we can defer SourceCode handling. It simply
|
||||||
@ -11,6 +11,13 @@ pub struct CliError<'src>(
|
|||||||
pub &'src StateWorkingSet<'src>,
|
pub &'src StateWorkingSet<'src>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
pub fn format_error(
|
||||||
|
working_set: &StateWorkingSet,
|
||||||
|
error: &(dyn miette::Diagnostic + Send + Sync + 'static),
|
||||||
|
) -> String {
|
||||||
|
return format!("Error: {:?}", CliError(error, working_set));
|
||||||
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for CliError<'_> {
|
impl std::fmt::Debug for CliError<'_> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
MietteHandler::default().debug(self, f)?;
|
MietteHandler::default().debug(self, f)?;
|
@ -1,4 +1,5 @@
|
|||||||
pub mod ast;
|
pub mod ast;
|
||||||
|
mod cli_error;
|
||||||
mod config;
|
mod config;
|
||||||
pub mod engine;
|
pub mod engine;
|
||||||
mod example;
|
mod example;
|
||||||
@ -14,6 +15,7 @@ mod ty;
|
|||||||
mod value;
|
mod value;
|
||||||
mod variable;
|
mod variable;
|
||||||
|
|
||||||
|
pub use cli_error::*;
|
||||||
pub use config::*;
|
pub use config::*;
|
||||||
pub use engine::{ENV_VARIABLE_ID, IN_VARIABLE_ID, NU_VARIABLE_ID};
|
pub use engine::{ENV_VARIABLE_ID, IN_VARIABLE_ID, NU_VARIABLE_ID};
|
||||||
pub use example::*;
|
pub use example::*;
|
||||||
|
@ -455,11 +455,6 @@ impl PipelineData {
|
|||||||
|
|
||||||
for item in table {
|
for item in table {
|
||||||
let stdout = std::io::stdout();
|
let stdout = std::io::stdout();
|
||||||
|
|
||||||
if let Value::Error { error } = item {
|
|
||||||
return Err(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut out = item.into_string("\n", config);
|
let mut out = item.into_string("\n", config);
|
||||||
out.push('\n');
|
out.push('\n');
|
||||||
|
|
||||||
@ -472,11 +467,6 @@ impl PipelineData {
|
|||||||
None => {
|
None => {
|
||||||
for item in self {
|
for item in self {
|
||||||
let stdout = std::io::stdout();
|
let stdout = std::io::stdout();
|
||||||
|
|
||||||
if let Value::Error { error } = item {
|
|
||||||
return Err(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut out = item.into_string("\n", config);
|
let mut out = item.into_string("\n", config);
|
||||||
out.push('\n');
|
out.push('\n');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user