|
|
|
@ -1,86 +1,20 @@
|
|
|
|
|
use miette::Diagnostic;
|
|
|
|
|
use nu_parser::ParseError;
|
|
|
|
|
use nu_protocol::ShellError;
|
|
|
|
|
use nu_protocol::{ParseError, ShellError};
|
|
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
|
|
pub type CrateResult<T> = std::result::Result<T, CrateError>;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Error)]
|
|
|
|
|
#[derive(Clone, Debug, Error, Diagnostic)]
|
|
|
|
|
pub enum CrateError {
|
|
|
|
|
#[error("Shell Error {0}")]
|
|
|
|
|
#[diagnostic()]
|
|
|
|
|
NuShellError(#[from] ShellError),
|
|
|
|
|
|
|
|
|
|
#[error("Parse Error {0}")]
|
|
|
|
|
NuParseError(#[from] ParseError),
|
|
|
|
|
#[error("Parse Error {0:?}")]
|
|
|
|
|
#[diagnostic()]
|
|
|
|
|
NuParseErrors(Vec<ParseError>),
|
|
|
|
|
|
|
|
|
|
#[error("Could not find the function {0}")]
|
|
|
|
|
#[diagnostic()]
|
|
|
|
|
FunctionNotFound(String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Diagnostic for CrateError {
|
|
|
|
|
fn code<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
|
|
|
|
|
match self {
|
|
|
|
|
CrateError::NuShellError(n) => n.code(),
|
|
|
|
|
CrateError::NuParseError(n) => n.code(),
|
|
|
|
|
Self::FunctionNotFound(_) => Some(Box::new("embed_nu::fn_not_found")),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn severity(&self) -> Option<miette::Severity> {
|
|
|
|
|
match self {
|
|
|
|
|
CrateError::NuShellError(n) => n.severity(),
|
|
|
|
|
CrateError::NuParseError(n) => n.severity(),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn help<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
|
|
|
|
|
match self {
|
|
|
|
|
CrateError::NuShellError(n) => n.help(),
|
|
|
|
|
CrateError::NuParseError(n) => n.help(),
|
|
|
|
|
CrateError::FunctionNotFound(_) => Some(Box::new(
|
|
|
|
|
"Make sure the function you want to execute is defined at this point.",
|
|
|
|
|
)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn url<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
|
|
|
|
|
match self {
|
|
|
|
|
CrateError::NuShellError(n) => n.url(),
|
|
|
|
|
CrateError::NuParseError(n) => n.url(),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn source_code(&self) -> Option<&dyn miette::SourceCode> {
|
|
|
|
|
match self {
|
|
|
|
|
CrateError::NuShellError(n) => n.source_code(),
|
|
|
|
|
CrateError::NuParseError(n) => n.source_code(),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn labels(&self) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + '_>> {
|
|
|
|
|
match self {
|
|
|
|
|
CrateError::NuShellError(n) => n.labels(),
|
|
|
|
|
CrateError::NuParseError(n) => n.labels(),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
|
|
|
|
|
match self {
|
|
|
|
|
CrateError::NuShellError(n) => n.related(),
|
|
|
|
|
CrateError::NuParseError(n) => n.related(),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn diagnostic_source(&self) -> Option<&dyn Diagnostic> {
|
|
|
|
|
match self {
|
|
|
|
|
CrateError::NuShellError(n) => n.diagnostic_source(),
|
|
|
|
|
CrateError::NuParseError(n) => n.diagnostic_source(),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|