mirror of
https://github.com/nushell/nushell.git
synced 2025-08-12 17:07:15 +02:00
Rust 1.85, edition=2024 (#15741)
This commit is contained in:
@ -2,8 +2,8 @@
|
||||
//!
|
||||
//! Relies on the `miette` crate for pretty layout
|
||||
use crate::{
|
||||
engine::{EngineState, StateWorkingSet},
|
||||
CompileError, ErrorStyle, ParseError, ParseWarning, ShellError,
|
||||
engine::{EngineState, StateWorkingSet},
|
||||
};
|
||||
use miette::{
|
||||
LabeledSpan, MietteHandlerOpts, NarratableReportHandler, ReportHandler, RgbColors, Severity,
|
||||
|
@ -17,14 +17,18 @@ pub enum CompileError {
|
||||
#[error("Register {reg_id} was uninitialized when used, possibly reused.")]
|
||||
#[diagnostic(
|
||||
code(nu::compile::register_uninitialized),
|
||||
help("this is a compiler bug. Please report it at https://github.com/nushell/nushell/issues/new\nfrom: {caller}"),
|
||||
help(
|
||||
"this is a compiler bug. Please report it at https://github.com/nushell/nushell/issues/new\nfrom: {caller}"
|
||||
)
|
||||
)]
|
||||
RegisterUninitialized { reg_id: RegId, caller: String },
|
||||
|
||||
#[error("Register {reg_id} was uninitialized when used, possibly reused.")]
|
||||
#[diagnostic(
|
||||
code(nu::compile::register_uninitialized),
|
||||
help("this is a compiler bug. Please report it at https://github.com/nushell/nushell/issues/new\nfrom: {caller}"),
|
||||
help(
|
||||
"this is a compiler bug. Please report it at https://github.com/nushell/nushell/issues/new\nfrom: {caller}"
|
||||
)
|
||||
)]
|
||||
RegisterUninitializedWhilePushingInstruction {
|
||||
reg_id: RegId,
|
||||
@ -57,7 +61,9 @@ pub enum CompileError {
|
||||
#[error("Invalid redirect mode: File should not be specified by commands.")]
|
||||
#[diagnostic(
|
||||
code(nu::compile::invalid_redirect_mode),
|
||||
help("this is a command bug. Please report it at https://github.com/nushell/nushell/issues/new")
|
||||
help(
|
||||
"this is a command bug. Please report it at https://github.com/nushell/nushell/issues/new"
|
||||
)
|
||||
)]
|
||||
InvalidRedirectMode {
|
||||
#[label("while compiling this expression")]
|
||||
@ -96,7 +102,9 @@ pub enum CompileError {
|
||||
#[error("Attempted to set branch target of non-branch instruction.")]
|
||||
#[diagnostic(
|
||||
code(nu::compile::set_branch_target_of_non_branch_instruction),
|
||||
help("this is a compiler bug. Please report it at https://github.com/nushell/nushell/issues/new"),
|
||||
help(
|
||||
"this is a compiler bug. Please report it at https://github.com/nushell/nushell/issues/new"
|
||||
)
|
||||
)]
|
||||
SetBranchTargetOfNonBranchInstruction {
|
||||
instruction: String,
|
||||
@ -218,7 +226,9 @@ pub enum CompileError {
|
||||
#[error("Incoherent loop state: the loop that ended was not the one we were expecting.")]
|
||||
#[diagnostic(
|
||||
code(nu::compile::incoherent_loop_state),
|
||||
help("this is a compiler bug. Please report it at https://github.com/nushell/nushell/issues/new"),
|
||||
help(
|
||||
"this is a compiler bug. Please report it at https://github.com/nushell/nushell/issues/new"
|
||||
)
|
||||
)]
|
||||
IncoherentLoopState {
|
||||
#[label("while compiling this block")]
|
||||
@ -228,7 +238,9 @@ pub enum CompileError {
|
||||
#[error("Undefined label `{label_id}`.")]
|
||||
#[diagnostic(
|
||||
code(nu::compile::undefined_label),
|
||||
help("this is a compiler bug. Please report it at https://github.com/nushell/nushell/issues/new"),
|
||||
help(
|
||||
"this is a compiler bug. Please report it at https://github.com/nushell/nushell/issues/new"
|
||||
)
|
||||
)]
|
||||
UndefinedLabel {
|
||||
label_id: usize,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use super::{shell_error::io::IoError, ShellError};
|
||||
use super::{ShellError, shell_error::io::IoError};
|
||||
use crate::Span;
|
||||
use miette::Diagnostic;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -1,9 +1,9 @@
|
||||
use crate::{ast::RedirectionSource, did_you_mean, Span, Type};
|
||||
use crate::{Span, Type, ast::RedirectionSource, did_you_mean};
|
||||
use miette::Diagnostic;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
fmt::Display,
|
||||
str::{from_utf8, Utf8Error},
|
||||
str::{Utf8Error, from_utf8},
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
@ -245,14 +245,18 @@ pub enum ParseError {
|
||||
#[error("Module not found.")]
|
||||
#[diagnostic(
|
||||
code(nu::parser::module_not_found),
|
||||
help("module files and their paths must be available before your script is run as parsing occurs before anything is evaluated")
|
||||
help(
|
||||
"module files and their paths must be available before your script is run as parsing occurs before anything is evaluated"
|
||||
)
|
||||
)]
|
||||
ModuleNotFound(#[label = "module {1} not found"] Span, String),
|
||||
|
||||
#[error("Missing mod.nu file.")]
|
||||
#[diagnostic(
|
||||
code(nu::parser::module_missing_mod_nu_file),
|
||||
help("Directory {0} is missing a mod.nu file.\n\nWhen importing a directory as a Nushell module, it needs to contain a mod.nu file (can be empty). Alternatively, you can use .nu files in the directory as modules individually.")
|
||||
help(
|
||||
"Directory {0} is missing a mod.nu file.\n\nWhen importing a directory as a Nushell module, it needs to contain a mod.nu file (can be empty). Alternatively, you can use .nu files in the directory as modules individually."
|
||||
)
|
||||
)]
|
||||
ModuleMissingModNuFile(
|
||||
String,
|
||||
@ -266,7 +270,9 @@ pub enum ParseError {
|
||||
#[error("Can't export {0} named same as the module.")]
|
||||
#[diagnostic(
|
||||
code(nu::parser::named_as_module),
|
||||
help("Module {1} can't export {0} named the same as the module. Either change the module name, or export `{2}` {0}.")
|
||||
help(
|
||||
"Module {1} can't export {0} named the same as the module. Either change the module name, or export `{2}` {0}."
|
||||
)
|
||||
)]
|
||||
NamedAsModule(
|
||||
String,
|
||||
@ -288,7 +294,9 @@ pub enum ParseError {
|
||||
#[error("Can't export alias defined as 'main'.")]
|
||||
#[diagnostic(
|
||||
code(nu::parser::export_main_alias_not_allowed),
|
||||
help("Exporting aliases as 'main' is not allowed. Either rename the alias or convert it to a custom command.")
|
||||
help(
|
||||
"Exporting aliases as 'main' is not allowed. Either rename the alias or convert it to a custom command."
|
||||
)
|
||||
)]
|
||||
ExportMainAliasNotAllowed(#[label = "can't export from module"] Span),
|
||||
|
||||
@ -299,7 +307,9 @@ pub enum ParseError {
|
||||
#[error("Overlay prefix mismatch.")]
|
||||
#[diagnostic(
|
||||
code(nu::parser::overlay_prefix_mismatch),
|
||||
help("Overlay {0} already exists {1} a prefix. To add it again, do it {1} the --prefix flag.")
|
||||
help(
|
||||
"Overlay {0} already exists {1} a prefix. To add it again, do it {1} the --prefix flag."
|
||||
)
|
||||
)]
|
||||
OverlayPrefixMismatch(
|
||||
String,
|
||||
@ -310,7 +320,9 @@ pub enum ParseError {
|
||||
#[error("Module or overlay not found.")]
|
||||
#[diagnostic(
|
||||
code(nu::parser::module_or_overlay_not_found),
|
||||
help("Requires either an existing overlay, a module, or an import pattern defining a module.")
|
||||
help(
|
||||
"Requires either an existing overlay, a module, or an import pattern defining a module."
|
||||
)
|
||||
)]
|
||||
ModuleOrOverlayNotFound(#[label = "not a module or an overlay"] Span),
|
||||
|
||||
@ -474,7 +486,9 @@ pub enum ParseError {
|
||||
#[error("Plugin not found")]
|
||||
#[diagnostic(
|
||||
code(nu::parser::plugin_not_found),
|
||||
help("plugins need to be added to the plugin registry file before your script is run (see `plugin add`)"),
|
||||
help(
|
||||
"plugins need to be added to the plugin registry file before your script is run (see `plugin add`)"
|
||||
)
|
||||
)]
|
||||
PluginNotFound {
|
||||
name: String,
|
||||
@ -513,7 +527,9 @@ pub enum ParseError {
|
||||
#[error("This command does not have a ...rest parameter")]
|
||||
#[diagnostic(
|
||||
code(nu::parser::unexpected_spread_arg),
|
||||
help("To spread arguments, the command needs to define a multi-positional parameter in its signature, such as ...rest")
|
||||
help(
|
||||
"To spread arguments, the command needs to define a multi-positional parameter in its signature, such as ...rest"
|
||||
)
|
||||
)]
|
||||
UnexpectedSpreadArg(String, #[label = "unexpected spread argument"] Span),
|
||||
|
||||
|
@ -10,7 +10,9 @@ pub enum ParseWarning {
|
||||
DeprecatedWarning {
|
||||
old_command: String,
|
||||
new_suggestion: String,
|
||||
#[label("`{old_command}` is deprecated and will be removed in a future release. Please {new_suggestion} instead.")]
|
||||
#[label(
|
||||
"`{old_command}` is deprecated and will be removed in a future release. Please {new_suggestion} instead."
|
||||
)]
|
||||
span: Span,
|
||||
url: String,
|
||||
},
|
||||
|
@ -8,7 +8,7 @@ use thiserror::Error;
|
||||
|
||||
use crate::Span;
|
||||
|
||||
use super::{location::Location, ShellError};
|
||||
use super::{ShellError, location::Location};
|
||||
|
||||
/// Represents an I/O error in the [`ShellError::Io`] variant.
|
||||
///
|
||||
|
@ -1,7 +1,7 @@
|
||||
use super::chained_error::ChainedError;
|
||||
use crate::{
|
||||
ast::Operator, engine::StateWorkingSet, format_shell_error, record, ConfigError, LabeledError,
|
||||
ParseError, Span, Spanned, Type, Value,
|
||||
ConfigError, LabeledError, ParseError, Span, Spanned, Type, Value, ast::Operator,
|
||||
engine::StateWorkingSet, format_shell_error, record,
|
||||
};
|
||||
use miette::Diagnostic;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -312,8 +312,9 @@ pub enum ShellError {
|
||||
#[diagnostic(
|
||||
code(nu::shell::nushell_failed),
|
||||
help(
|
||||
"This shouldn't happen. Please file an issue: https://github.com/nushell/nushell/issues"
|
||||
))]
|
||||
"This shouldn't happen. Please file an issue: https://github.com/nushell/nushell/issues"
|
||||
)
|
||||
)]
|
||||
// Only use this one if Nushell completely falls over and hits a state that isn't possible or isn't recoverable
|
||||
NushellFailed { msg: String },
|
||||
|
||||
@ -326,8 +327,9 @@ pub enum ShellError {
|
||||
#[diagnostic(
|
||||
code(nu::shell::nushell_failed_spanned),
|
||||
help(
|
||||
"This shouldn't happen. Please file an issue: https://github.com/nushell/nushell/issues"
|
||||
))]
|
||||
"This shouldn't happen. Please file an issue: https://github.com/nushell/nushell/issues"
|
||||
)
|
||||
)]
|
||||
// Only use this one if Nushell completely falls over and hits a state that isn't possible or isn't recoverable
|
||||
NushellFailedSpanned {
|
||||
msg: String,
|
||||
@ -823,7 +825,9 @@ pub enum ShellError {
|
||||
plugin_name: String,
|
||||
#[label("plugin `{plugin_name}` loaded here")]
|
||||
span: Option<Span>,
|
||||
#[help("the format in the plugin registry file is not compatible with this version of Nushell.\n\nTry adding the plugin again with `{}`")]
|
||||
#[help(
|
||||
"the format in the plugin registry file is not compatible with this version of Nushell.\n\nTry adding the plugin again with `{}`"
|
||||
)]
|
||||
add_command: String,
|
||||
},
|
||||
|
||||
@ -893,9 +897,7 @@ pub enum ShellError {
|
||||
/// creation of the custom value and its use.
|
||||
#[error("Custom value failed to decode")]
|
||||
#[diagnostic(code(nu::shell::custom_value_failed_to_decode))]
|
||||
#[diagnostic(help(
|
||||
"the plugin may have been updated and no longer support this custom value"
|
||||
))]
|
||||
#[diagnostic(help("the plugin may have been updated and no longer support this custom value"))]
|
||||
CustomValueFailedToDecode {
|
||||
msg: String,
|
||||
#[label("{msg}")]
|
||||
@ -1167,7 +1169,9 @@ This is an internal Nushell error, please file an issue https://github.com/nushe
|
||||
#[error("Not a constant.")]
|
||||
#[diagnostic(
|
||||
code(nu::shell::not_a_constant),
|
||||
help("Only a subset of expressions are allowed constants during parsing. Try using the 'const' command or typing the value literally.")
|
||||
help(
|
||||
"Only a subset of expressions are allowed constants during parsing. Try using the 'const' command or typing the value literally."
|
||||
)
|
||||
)]
|
||||
NotAConstant {
|
||||
#[label("Value is not a parse-time constant")]
|
||||
@ -1183,7 +1187,9 @@ This is an internal Nushell error, please file an issue https://github.com/nushe
|
||||
#[error("Not a const command.")]
|
||||
#[diagnostic(
|
||||
code(nu::shell::not_a_const_command),
|
||||
help("Only a subset of builtin commands, and custom commands built only from those commands, can run at parse time.")
|
||||
help(
|
||||
"Only a subset of builtin commands, and custom commands built only from those commands, can run at parse time."
|
||||
)
|
||||
)]
|
||||
NotAConstCommand {
|
||||
#[label("This command cannot run at parse time.")]
|
||||
@ -1240,7 +1246,9 @@ This is an internal Nushell error, please file an issue https://github.com/nushe
|
||||
#[error("Not a list")]
|
||||
#[diagnostic(
|
||||
code(nu::shell::cannot_spread_as_list),
|
||||
help("Only lists can be spread inside lists and command calls. Try converting the value to a list before spreading.")
|
||||
help(
|
||||
"Only lists can be spread inside lists and command calls. Try converting the value to a list before spreading."
|
||||
)
|
||||
)]
|
||||
CannotSpreadAsList {
|
||||
#[label = "cannot spread value"]
|
||||
@ -1255,7 +1263,9 @@ This is an internal Nushell error, please file an issue https://github.com/nushe
|
||||
#[error("Not a record")]
|
||||
#[diagnostic(
|
||||
code(nu::shell::cannot_spread_as_record),
|
||||
help("Only records can be spread inside records. Try converting the value to a record before spreading.")
|
||||
help(
|
||||
"Only records can be spread inside records. Try converting the value to a record before spreading."
|
||||
)
|
||||
)]
|
||||
CannotSpreadAsRecord {
|
||||
#[label = "cannot spread value"]
|
||||
@ -1310,7 +1320,9 @@ On Windows, this would be %USERPROFILE%\AppData\Roaming"#
|
||||
},
|
||||
|
||||
/// XDG_CONFIG_HOME was set to an invalid path
|
||||
#[error("$env.XDG_CONFIG_HOME ({xdg}) is invalid, using default config directory instead: {default}")]
|
||||
#[error(
|
||||
"$env.XDG_CONFIG_HOME ({xdg}) is invalid, using default config directory instead: {default}"
|
||||
)]
|
||||
#[diagnostic(
|
||||
code(nu::shell::xdg_config_home_invalid),
|
||||
help("Set XDG_CONFIG_HOME to an absolute path, or set it to an empty string to ignore it")
|
||||
@ -1326,7 +1338,9 @@ On Windows, this would be %USERPROFILE%\AppData\Roaming"#
|
||||
#[error("IR evaluation error: {msg}")]
|
||||
#[diagnostic(
|
||||
code(nu::shell::ir_eval_error),
|
||||
help("this is a bug, please report it at https://github.com/nushell/nushell/issues/new along with the code you were running if able")
|
||||
help(
|
||||
"this is a bug, please report it at https://github.com/nushell/nushell/issues/new along with the code you were running if able"
|
||||
)
|
||||
)]
|
||||
IrEvalError {
|
||||
msg: String,
|
||||
@ -1568,19 +1582,25 @@ mod test {
|
||||
|
||||
impl From<std::io::Error> for ShellError {
|
||||
fn from(_: std::io::Error) -> ShellError {
|
||||
unimplemented!("This implementation is defined in the test module to ensure no other implementation exists.")
|
||||
unimplemented!(
|
||||
"This implementation is defined in the test module to ensure no other implementation exists."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Spanned<std::io::Error>> for ShellError {
|
||||
fn from(_: Spanned<std::io::Error>) -> Self {
|
||||
unimplemented!("This implementation is defined in the test module to ensure no other implementation exists.")
|
||||
unimplemented!(
|
||||
"This implementation is defined in the test module to ensure no other implementation exists."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ShellError> for std::io::Error {
|
||||
fn from(_: ShellError) -> Self {
|
||||
unimplemented!("This implementation is defined in the test module to ensure no other implementation exists.")
|
||||
unimplemented!(
|
||||
"This implementation is defined in the test module to ensure no other implementation exists."
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user