Refactor config updates (#13802)

# Description
This PR standardizes updates to the config through a new
`UpdateFromValue` trait. For now, this trait is private in case we need
to make changes to it.

Note that this PR adds some additional `ShellError` cases to create
standard error messages for config errors. A follow-up PR will move
usages of the old error cases to these new ones. This PR also uses
`Type::custom` in lots of places (e.g., for string enums). Not sure if
this is something we want to encourage.

# User-Facing Changes
Should be none.
This commit is contained in:
Ian Manske
2024-10-11 09:40:32 -07:00
committed by GitHub
parent 02313e6819
commit fce6146576
32 changed files with 1343 additions and 1487 deletions

View File

@ -2,10 +2,9 @@ use nu_cmd_base::hook::{eval_env_change_hook, eval_hook};
use nu_engine::eval_block;
use nu_parser::parse;
use nu_protocol::{
cli_error::CliError,
debugger::WithoutDebug,
engine::{EngineState, Stack, StateWorkingSet},
PipelineData, Value,
report_parse_error, report_shell_error, PipelineData, ShellError, Value,
};
use nu_std::load_standard_library;
use std::{
@ -209,20 +208,13 @@ pub fn chop() {
std::process::exit(0);
}
fn outcome_err(
engine_state: &EngineState,
error: &(dyn miette::Diagnostic + Send + Sync + 'static),
) -> ! {
let working_set = StateWorkingSet::new(engine_state);
eprintln!("Error: {:?}", CliError(error, &working_set));
fn outcome_err(engine_state: &EngineState, error: &ShellError) -> ! {
report_shell_error(engine_state, error);
std::process::exit(1);
}
fn outcome_ok(msg: String) -> ! {
println!("{msg}");
std::process::exit(0);
}
@ -320,7 +312,8 @@ pub fn nu_repl() {
);
if let Some(err) = working_set.parse_errors.first() {
outcome_err(&engine_state, err);
report_parse_error(&working_set, err);
std::process::exit(1);
}
(block, working_set.render())
};