diff --git a/Cargo.lock b/Cargo.lock index 4960f54dd9..e01e670a1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3019,7 +3019,6 @@ name = "nu-std" version = "0.78.1" dependencies = [ "miette", - "nu-cli", "nu-parser", "nu-protocol", ] diff --git a/crates/nu-cli/src/commands.rs b/crates/nu-cli/src/commands.rs index 3811143c31..6eae2163c2 100644 --- a/crates/nu-cli/src/commands.rs +++ b/crates/nu-cli/src/commands.rs @@ -1,9 +1,9 @@ use log::info; use miette::Result; -use nu_command::util::report_error; use nu_engine::{convert_env_values, eval_block}; use nu_parser::parse; use nu_protocol::engine::Stack; +use nu_protocol::report_error; use nu_protocol::{ engine::{EngineState, StateWorkingSet}, PipelineData, Spanned, Value, diff --git a/crates/nu-cli/src/config_files.rs b/crates/nu-cli/src/config_files.rs index fb5826c083..5199a1b051 100644 --- a/crates/nu-cli/src/config_files.rs +++ b/crates/nu-cli/src/config_files.rs @@ -1,8 +1,8 @@ use crate::util::eval_source; -use nu_command::util::report_error; #[cfg(feature = "plugin")] use nu_path::canonicalize_with; use nu_protocol::engine::{EngineState, Stack, StateWorkingSet}; +use nu_protocol::report_error; use nu_protocol::{HistoryFileFormat, PipelineData}; #[cfg(feature = "plugin")] use nu_protocol::{ParseError, Spanned}; diff --git a/crates/nu-cli/src/eval_file.rs b/crates/nu-cli/src/eval_file.rs index e1948a88ee..b14fe5fb2c 100644 --- a/crates/nu-cli/src/eval_file.rs +++ b/crates/nu-cli/src/eval_file.rs @@ -2,10 +2,10 @@ use crate::util::eval_source; use log::info; use log::trace; use miette::{IntoDiagnostic, Result}; -use nu_command::util::report_error; use nu_engine::{convert_env_values, current_dir}; use nu_parser::parse; use nu_path::canonicalize_with; +use nu_protocol::report_error; use nu_protocol::{ ast::Call, engine::{EngineState, Stack, StateWorkingSet}, diff --git a/crates/nu-cli/src/lib.rs b/crates/nu-cli/src/lib.rs index 97e042b328..890124d599 100644 --- a/crates/nu-cli/src/lib.rs +++ b/crates/nu-cli/src/lib.rs @@ -18,7 +18,7 @@ pub use completions::{FileCompletion, NuCompleter}; pub use config_files::eval_config_contents; pub use eval_file::evaluate_file; pub use menus::{DescriptionMenu, NuHelpCompleter}; -pub use nu_command::util::{get_init_cwd, report_error, report_error_new}; +pub use nu_command::util::get_init_cwd; pub use nu_highlight::NuHighlight; pub use print::Print; pub use prompt::NushellPrompt; diff --git a/crates/nu-cli/src/prompt_update.rs b/crates/nu-cli/src/prompt_update.rs index c8c21fcdb0..127c02458b 100644 --- a/crates/nu-cli/src/prompt_update.rs +++ b/crates/nu-cli/src/prompt_update.rs @@ -1,7 +1,7 @@ use crate::NushellPrompt; use log::trace; -use nu_command::util::report_error; use nu_engine::eval_subexpression; +use nu_protocol::report_error; use nu_protocol::{ engine::{EngineState, Stack, StateWorkingSet}, Config, PipelineData, Value, diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 9c9731e1b1..861fc3fadd 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -10,13 +10,14 @@ use log::{trace, warn}; use miette::{IntoDiagnostic, Result}; use nu_color_config::StyleComputer; use nu_command::hook::eval_hook; -use nu_command::util::{get_guaranteed_cwd, report_error, report_error_new}; +use nu_command::util::get_guaranteed_cwd; use nu_engine::{convert_env_values, eval_block}; use nu_parser::{lex, parse, trim_quotes_str}; use nu_protocol::{ config::NuCursorShape, engine::{EngineState, Stack, StateWorkingSet}, - format_duration, HistoryFileFormat, PipelineData, ShellError, Span, Spanned, Value, + format_duration, report_error, report_error_new, HistoryFileFormat, PipelineData, ShellError, + Span, Spanned, Value, }; use nu_utils::utils::perf; use reedline::{CursorConfig, DefaultHinter, EditCommand, Emacs, SqliteBackedHistory, Vi}; diff --git a/crates/nu-cli/src/util.rs b/crates/nu-cli/src/util.rs index 60ec43a786..9cdbdf1573 100644 --- a/crates/nu-cli/src/util.rs +++ b/crates/nu-cli/src/util.rs @@ -1,5 +1,4 @@ use nu_command::hook::eval_hook; -use nu_command::util::{report_error, report_error_new}; use nu_engine::{eval_block, eval_block_with_early_return}; use nu_parser::{escape_quote_string, lex, parse, unescape_unquote_string, Token, TokenContents}; use nu_protocol::engine::StateWorkingSet; @@ -7,6 +6,7 @@ use nu_protocol::{ engine::{EngineState, Stack}, print_if_stream, PipelineData, ShellError, Span, Value, }; +use nu_protocol::{report_error, report_error_new}; #[cfg(windows)] use nu_utils::enable_vt_processing; use nu_utils::utils::perf; diff --git a/crates/nu-command/src/hook.rs b/crates/nu-command/src/hook.rs index f075d4077a..40b9a77a03 100644 --- a/crates/nu-command/src/hook.rs +++ b/crates/nu-command/src/hook.rs @@ -1,8 +1,9 @@ -use crate::util::{get_guaranteed_cwd, report_error, report_error_new}; +use crate::util::get_guaranteed_cwd; use miette::Result; use nu_engine::{eval_block, eval_block_with_early_return}; use nu_parser::parse; use nu_protocol::ast::PathMember; +use nu_protocol::cli_error::{report_error, report_error_new}; use nu_protocol::engine::{EngineState, Stack, StateWorkingSet}; use nu_protocol::{BlockId, PipelineData, PositionalArg, ShellError, Span, Type, Value, VarId}; diff --git a/crates/nu-command/src/util.rs b/crates/nu-command/src/util.rs index dff05b4089..f107ae447b 100644 --- a/crates/nu-command/src/util.rs +++ b/crates/nu-command/src/util.rs @@ -1,31 +1,11 @@ +use nu_protocol::report_error; use nu_protocol::{ ast::RangeInclusion, engine::{EngineState, Stack, StateWorkingSet}, - CliError, Range, ShellError, Span, Value, + Range, ShellError, Span, Value, }; use std::path::PathBuf; -pub fn report_error( - working_set: &StateWorkingSet, - error: &(dyn miette::Diagnostic + Send + Sync + 'static), -) { - eprintln!("Error: {:?}", CliError(error, working_set)); - // reset vt processing, aka ansi because illbehaved externals can break it - #[cfg(windows)] - { - let _ = nu_utils::enable_vt_processing(); - } -} - -pub fn report_error_new( - engine_state: &EngineState, - error: &(dyn miette::Diagnostic + Send + Sync + 'static), -) { - let working_set = StateWorkingSet::new(engine_state); - - report_error(&working_set, error); -} - pub fn get_init_cwd() -> PathBuf { std::env::current_dir().unwrap_or_else(|_| { std::env::var("PWD") diff --git a/crates/nu-protocol/src/cli_error.rs b/crates/nu-protocol/src/cli_error.rs index 1626abb841..b563ff003c 100644 --- a/crates/nu-protocol/src/cli_error.rs +++ b/crates/nu-protocol/src/cli_error.rs @@ -1,4 +1,4 @@ -use crate::engine::StateWorkingSet; +use crate::engine::{EngineState, StateWorkingSet}; use miette::{LabeledSpan, MietteHandlerOpts, ReportHandler, RgbColors, Severity, SourceCode}; use thiserror::Error; @@ -18,6 +18,27 @@ pub fn format_error( format!("Error: {:?}", CliError(error, working_set)) } +pub fn report_error( + working_set: &StateWorkingSet, + error: &(dyn miette::Diagnostic + Send + Sync + 'static), +) { + eprintln!("Error: {:?}", CliError(error, working_set)); + // reset vt processing, aka ansi because illbehaved externals can break it + #[cfg(windows)] + { + let _ = nu_utils::enable_vt_processing(); + } +} + +pub fn report_error_new( + engine_state: &EngineState, + error: &(dyn miette::Diagnostic + Send + Sync + 'static), +) { + let working_set = StateWorkingSet::new(engine_state); + + report_error(&working_set, error); +} + impl std::fmt::Debug for CliError<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let ansi_support = self.1.get_config().use_ansi_coloring; diff --git a/crates/nu-protocol/src/lib.rs b/crates/nu-protocol/src/lib.rs index 6e47d44bf3..4b9d2361e6 100644 --- a/crates/nu-protocol/src/lib.rs +++ b/crates/nu-protocol/src/lib.rs @@ -1,6 +1,6 @@ mod alias; pub mod ast; -mod cli_error; +pub mod cli_error; pub mod config; pub mod engine; mod example; diff --git a/crates/nu-std/Cargo.toml b/crates/nu-std/Cargo.toml index 22c6b5bbec..097e86b246 100644 --- a/crates/nu-std/Cargo.toml +++ b/crates/nu-std/Cargo.toml @@ -9,6 +9,5 @@ version = "0.78.1" [dependencies] miette = { version = "5.6.0", features = ["fancy-no-backtrace"] } -nu-cli = { version = "0.78.1", path = "../nu-cli" } nu-parser = { version = "0.78.1", path = "../nu-parser" } nu-protocol = { version = "0.78.1", path = "../nu-protocol" } diff --git a/crates/nu-std/src/lib.rs b/crates/nu-std/src/lib.rs index 8597e00e36..627c42d72f 100644 --- a/crates/nu-std/src/lib.rs +++ b/crates/nu-std/src/lib.rs @@ -1,5 +1,5 @@ -use nu_cli::report_error; use nu_parser::{parse, parse_module_block}; +use nu_protocol::report_error; use nu_protocol::{engine::StateWorkingSet, Module, ShellError, Span}; fn get_standard_library() -> &'static str { diff --git a/src/command.rs b/src/command.rs index 2c7050ecbd..e4e502e8c4 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1,7 +1,7 @@ -use nu_command::util::report_error; use nu_engine::{get_full_help, CallExt}; use nu_parser::parse; use nu_parser::{escape_for_script_arg, escape_quote_string}; +use nu_protocol::report_error; use nu_protocol::{ ast::{Call, Expr, Expression, PipelineElement}, engine::{Command, EngineState, Stack, StateWorkingSet}, diff --git a/src/config_files.rs b/src/config_files.rs index f061cb0542..be8632b6c2 100644 --- a/src/config_files.rs +++ b/src/config_files.rs @@ -2,9 +2,9 @@ use log::info; #[cfg(feature = "plugin")] use nu_cli::read_plugin_file; use nu_cli::{eval_config_contents, eval_source}; -use nu_command::util::report_error; use nu_path::canonicalize_with; use nu_protocol::engine::{EngineState, Stack, StateWorkingSet}; +use nu_protocol::report_error; use nu_protocol::{ParseError, PipelineData, Spanned}; use nu_utils::{get_default_config, get_default_env}; use std::fs::File; diff --git a/src/ide.rs b/src/ide.rs index 11fe5617f3..18e249a90f 100644 --- a/src/ide.rs +++ b/src/ide.rs @@ -1,6 +1,7 @@ use miette::IntoDiagnostic; -use nu_cli::{report_error, NuCompleter}; +use nu_cli::NuCompleter; use nu_parser::{flatten_block, parse, FlatShape}; +use nu_protocol::report_error; use nu_protocol::{ engine::{EngineState, Stack, StateWorkingSet}, DeclId, ShellError, Span, Value, VarId, diff --git a/src/main.rs b/src/main.rs index 87a3f809bb..1f64e2c191 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,8 +19,8 @@ use command::gather_commandline_args; use log::Level; use miette::Result; use nu_cli::gather_parent_env_vars; -use nu_command::util::report_error_new; use nu_command::{create_default_context, get_init_cwd}; +use nu_protocol::report_error_new; use nu_protocol::{util::BufferedReader, PipelineData, RawStream}; use nu_utils::utils::perf; use run::{run_commands, run_file, run_repl};