mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 05:55:12 +02:00
Better error handling using do
(#5890)
* adds `capture-errors` flag for `do` * adds `get-type` core command to get type * fmt * add tests in example * fmt * fix tests * manually revert previous changes related to `get-type` * adds method to check for error name using `into string` * fix clippy
This commit is contained in:
@ -724,6 +724,10 @@ impl From<Box<dyn std::error::Error + Send + Sync>> for ShellError {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_code(err: &ShellError) -> Option<String> {
|
||||
err.code().map(|code| code.to_string())
|
||||
}
|
||||
|
||||
pub fn did_you_mean(possibilities: &[String], tried: &str) -> Option<String> {
|
||||
let mut possible_matches: Vec<_> = possibilities
|
||||
.iter()
|
||||
|
@ -92,6 +92,9 @@ pub enum SyntaxShape {
|
||||
/// A record value
|
||||
Record,
|
||||
|
||||
/// An error value
|
||||
Error,
|
||||
|
||||
/// A custom shape with custom completion logic
|
||||
Custom(Box<SyntaxShape>, DeclId),
|
||||
}
|
||||
@ -112,6 +115,7 @@ impl SyntaxShape {
|
||||
SyntaxShape::Filesize => Type::Filesize,
|
||||
SyntaxShape::FullCellPath => Type::Any,
|
||||
SyntaxShape::GlobPattern => Type::String,
|
||||
SyntaxShape::Error => Type::Error,
|
||||
SyntaxShape::ImportPattern => Type::Any,
|
||||
SyntaxShape::Int => Type::Int,
|
||||
SyntaxShape::List(x) => {
|
||||
@ -168,6 +172,7 @@ impl Display for SyntaxShape {
|
||||
SyntaxShape::Signature => write!(f, "signature"),
|
||||
SyntaxShape::Expression => write!(f, "expression"),
|
||||
SyntaxShape::Boolean => write!(f, "bool"),
|
||||
SyntaxShape::Error => write!(f, "error"),
|
||||
SyntaxShape::Custom(x, _) => write!(f, "custom<{}>", x),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user