mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 09:05:47 +02:00
update miette and switch to GenericErrors (#5222)
This commit is contained in:
@ -215,21 +215,11 @@ pub enum ShellError {
|
||||
/// Not all values can be coerced this way. Check the supported type(s) and try again.
|
||||
#[error("Can't convert to {0}.")]
|
||||
#[diagnostic(code(nu::shell::cant_convert), url(docsrs))]
|
||||
CantConvert(String, String, #[label("can't convert {1} to {0}")] Span),
|
||||
|
||||
/// Failed to convert a value of one type into a different type.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// Not all values can be coerced this way. Check the supported type(s) and try again, referring to the help text in the specific error message.
|
||||
#[error("Can't convert to {0}.")]
|
||||
#[diagnostic(code(nu::shell::cant_convert), url(docsrs), help("{3}"))]
|
||||
// Identical to above, but with help
|
||||
CantConvertWithHelp(
|
||||
CantConvert(
|
||||
String,
|
||||
String,
|
||||
#[label("can't convert {1} to {0}")] Span,
|
||||
String,
|
||||
#[help] Option<String>,
|
||||
),
|
||||
|
||||
/// An environment variable cannot be represented as a string.
|
||||
@ -473,7 +463,7 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
/// Make sure the directory in the error message actually exists before trying again.
|
||||
#[error("Directory not found")]
|
||||
#[diagnostic(code(nu::shell::directory_not_found), url(docsrs))]
|
||||
DirectoryNotFound(#[label("directory not found")] Span),
|
||||
DirectoryNotFound(#[label("directory not found")] Span, #[help] Option<String>),
|
||||
|
||||
/// Attempted to perform an operation on a directory that doesn't exist.
|
||||
///
|
||||
@ -484,15 +474,6 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
#[diagnostic(code(nu::shell::directory_not_found_custom), url(docsrs))]
|
||||
DirectoryNotFoundCustom(String, #[label("{0}")] Span),
|
||||
|
||||
/// Attempted to perform an operation on a directory that doesn't exist.
|
||||
///
|
||||
/// ## Resolution
|
||||
///
|
||||
/// Make sure the directory in the error message actually exists before trying again.
|
||||
#[error("Directory not found")]
|
||||
#[diagnostic(code(nu::shell::directory_not_found_help), url(docsrs), help("{1}"))]
|
||||
DirectoryNotFoundHelp(#[label("directory not found")] Span, String),
|
||||
|
||||
/// The requested move operation cannot be completed. This is typically because both paths exist,
|
||||
/// but are of different types. For example, you might be trying to overwrite an existing file with
|
||||
/// a directory.
|
||||
@ -621,32 +602,14 @@ Either make sure {0} is a string, or add a 'to_string' entry for it in ENV_CONVE
|
||||
/// This is a generic error type used for different situations.
|
||||
#[error("{0}")]
|
||||
#[diagnostic()]
|
||||
SpannedLabeledError(String, String, #[label("{1}")] Span),
|
||||
|
||||
/// This is a generic error type used for different situations.
|
||||
#[error("{0}")]
|
||||
#[diagnostic(help("{3}"))]
|
||||
SpannedLabeledErrorHelp(String, String, #[label("{1}")] Span, String),
|
||||
|
||||
/// This is a generic error type used for different situations.
|
||||
#[error("{0}")]
|
||||
#[diagnostic()]
|
||||
SpannedLabeledErrorRelated(
|
||||
GenericError(
|
||||
String,
|
||||
String,
|
||||
#[label("{1}")] Span,
|
||||
#[label("{1}")] Option<Span>,
|
||||
#[help] Option<String>,
|
||||
#[related] Vec<ShellError>,
|
||||
),
|
||||
|
||||
/// This is a generic error type used for different situations.
|
||||
#[error("{0}")]
|
||||
#[diagnostic(help("{1}"))]
|
||||
LabeledError(String, String),
|
||||
|
||||
/// This is a generic error type used for different situations.
|
||||
#[error("{0}")]
|
||||
UnlabeledError(String),
|
||||
|
||||
/// This is a generic error type used for different situations.
|
||||
#[error("{1}")]
|
||||
#[diagnostic()]
|
||||
|
@ -549,8 +549,12 @@ impl Command for BlockCommand {
|
||||
_call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<crate::PipelineData, crate::ShellError> {
|
||||
Err(ShellError::UnlabeledError(
|
||||
Err(ShellError::GenericError(
|
||||
"Internal error: can't run custom command with 'run', use block_id".to_string(),
|
||||
"".to_string(),
|
||||
None,
|
||||
None,
|
||||
Vec::new(),
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ impl Value {
|
||||
"f64".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -19,6 +20,7 @@ impl Value {
|
||||
"i64".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ impl FromValue for Spanned<i64> {
|
||||
"integer".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -53,6 +54,7 @@ impl FromValue for i64 {
|
||||
"integer".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -74,6 +76,7 @@ impl FromValue for Spanned<f64> {
|
||||
"float".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -88,6 +91,7 @@ impl FromValue for f64 {
|
||||
"float".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -131,6 +135,7 @@ impl FromValue for Spanned<usize> {
|
||||
"non-negative integer".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -165,6 +170,7 @@ impl FromValue for usize {
|
||||
"non-negative integer".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -180,6 +186,7 @@ impl FromValue for String {
|
||||
"string".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -196,6 +203,7 @@ impl FromValue for Spanned<String> {
|
||||
"string".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
))
|
||||
}
|
||||
},
|
||||
@ -216,6 +224,7 @@ impl FromValue for Vec<String> {
|
||||
"string".into(),
|
||||
c.get_type().to_string(),
|
||||
c.span()?,
|
||||
None,
|
||||
)),
|
||||
})
|
||||
.collect::<Result<Vec<String>, ShellError>>(),
|
||||
@ -223,6 +232,7 @@ impl FromValue for Vec<String> {
|
||||
"string".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -255,6 +265,7 @@ impl FromValue for CellPath {
|
||||
"cell path".into(),
|
||||
x.get_type().to_string(),
|
||||
span,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -268,6 +279,7 @@ impl FromValue for bool {
|
||||
"bool".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -284,6 +296,7 @@ impl FromValue for Spanned<bool> {
|
||||
"bool".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -297,6 +310,7 @@ impl FromValue for DateTime<FixedOffset> {
|
||||
"date".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -313,6 +327,7 @@ impl FromValue for Spanned<DateTime<FixedOffset>> {
|
||||
"date".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -326,6 +341,7 @@ impl FromValue for Range {
|
||||
"range".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -342,6 +358,7 @@ impl FromValue for Spanned<Range> {
|
||||
"range".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -356,6 +373,7 @@ impl FromValue for Vec<u8> {
|
||||
"binary data".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -373,6 +391,7 @@ impl FromValue for Spanned<PathBuf> {
|
||||
"range".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -387,6 +406,7 @@ impl FromValue for Vec<Value> {
|
||||
"Vector of values".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -401,6 +421,7 @@ impl FromValue for (Vec<String>, Vec<Value>) {
|
||||
"Record".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -417,6 +438,7 @@ impl FromValue for CaptureBlock {
|
||||
"Block".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -440,6 +462,7 @@ impl FromValue for Spanned<CaptureBlock> {
|
||||
"Block".into(),
|
||||
v.get_type().to_string(),
|
||||
v.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
@ -188,6 +188,7 @@ impl Value {
|
||||
"string".into(),
|
||||
"binary".into(),
|
||||
self.span()?,
|
||||
None,
|
||||
));
|
||||
}
|
||||
}),
|
||||
@ -195,6 +196,7 @@ impl Value {
|
||||
"string".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -215,6 +217,7 @@ impl Value {
|
||||
"string".into(),
|
||||
"binary".into(),
|
||||
self.span()?,
|
||||
None,
|
||||
))
|
||||
}
|
||||
}),
|
||||
@ -222,6 +225,7 @@ impl Value {
|
||||
"string".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -233,6 +237,7 @@ impl Value {
|
||||
"path".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -244,6 +249,7 @@ impl Value {
|
||||
"block".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -256,6 +262,7 @@ impl Value {
|
||||
"binary".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -267,6 +274,7 @@ impl Value {
|
||||
"record".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -278,6 +286,7 @@ impl Value {
|
||||
"list".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -289,6 +298,7 @@ impl Value {
|
||||
"boolean".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -301,6 +311,7 @@ impl Value {
|
||||
"float".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -312,6 +323,7 @@ impl Value {
|
||||
"integer".into(),
|
||||
x.get_type().to_string(),
|
||||
self.span()?,
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user