give ICE a proper error type

This commit is contained in:
Devyn Cairns 2024-06-18 22:21:59 -07:00
parent 3c4877b059
commit 037ea618c7
2 changed files with 25 additions and 19 deletions

View File

@ -591,36 +591,25 @@ enum CompileError {
impl CompileError { impl CompileError {
fn to_shell_error(self, mut span: Option<Span>) -> ShellError { fn to_shell_error(self, mut span: Option<Span>) -> ShellError {
let ice = "internal compiler error: ";
let message = match self { let message = match self {
CompileError::RegisterOverflow => format!("{ice}register overflow"), CompileError::RegisterOverflow => format!("register overflow"),
CompileError::RegisterUninitialized(reg_id) => { CompileError::RegisterUninitialized(reg_id) => {
format!("{ice}register {reg_id} is uninitialized when used, possibly reused") format!("register {reg_id} is uninitialized when used, possibly reused")
} }
CompileError::InvalidRedirectMode => { CompileError::InvalidRedirectMode => {
format!("{ice}invalid redirect mode: File should not be specified by commands") "invalid redirect mode: File should not be specified by commands".into()
}
CompileError::Garbage => {
format!("{ice}encountered garbage, likely due to parse error")
}
CompileError::UnsupportedOperatorExpression => {
format!("{ice}unsupported operator expression")
} }
CompileError::Garbage => "encountered garbage, likely due to parse error".into(),
CompileError::UnsupportedOperatorExpression => "unsupported operator expression".into(),
CompileError::AccessEnvByInt(local_span) => { CompileError::AccessEnvByInt(local_span) => {
span = Some(local_span); span = Some(local_span);
format!("{ice}attempted access of $env by integer path") "attempted access of $env by integer path".into()
} }
CompileError::Todo(msg) => { CompileError::Todo(msg) => {
format!("{ice}TODO: {msg}") format!("TODO: {msg}")
} }
}; };
ShellError::GenericError { ShellError::IrCompileError { message, span }
error: message,
msg: "while compiling this code".into(),
span,
help: Some("this is a bug, please report it at https://github.com/nushell/nushell/issues/new along with the code you were compiling if able".into()),
inner: vec![]
}
} }
} }

View File

@ -1369,6 +1369,23 @@ On Windows, this would be %USERPROFILE%\AppData\Roaming"#
help("Set XDG_CONFIG_HOME to an absolute path, or set it to an empty string to ignore it") help("Set XDG_CONFIG_HOME to an absolute path, or set it to an empty string to ignore it")
)] )]
InvalidXdgConfig { xdg: String, default: String }, InvalidXdgConfig { xdg: String, default: String },
/// An error occurred with the IR compiler.
///
/// ## Resolution
///
/// The IR compiler is in very early development, so code that can't be compiled is quite
/// expected. If you think it should be working, please report it to us.
#[error("internal compiler error: {message}")]
#[diagnostic(
code(nu::shell::ir_compile_error),
help("this is a bug, please report it at https://github.com/nushell/nushell/issues/new along with the code you were compiling if able")
)]
IrCompileError {
message: String,
#[label = "while compiling this code"]
span: Option<Span>,
},
} }
// TODO: Implement as From trait // TODO: Implement as From trait