mirror of
https://github.com/nushell/nushell.git
synced 2025-08-19 07:41:30 +02:00
Document and critically review ShellError
variants - Ep. 1 (#8229)
# Description The `ShellError` enum at the moment is kind of messy. Many variants are basic tuple structs where you always have to reference the implementation with its macro invocation to know which field serves which purpose. Furthermore we have both variants that are kind of redundant or either overly broad to be useful for the user to match on or overly specific with few uses. So I set out to start fixing the lacking documentation and naming to make it feasible to critically review the individual usages and fix those. Furthermore we can decide to join or split up variants that don't seem to be fit for purpose. Feel free to add review comments if you spot inconsistent use of `ShellError` variants. - Name fields on `ShellError::OperatorOverflow` - Name fields on `ShellError::PipelineMismatch` - Add doc to `ShellError::OnlySupportsThisInputType` - Name `ShellError::OnlySupportsThisInputType` - Name field on `ShellError::PipelineEmpty` - Comment about issues with `TypeMismatch*` - Fix a few `exp_input_type`s - Name fields on `ShellError::InvalidRange` # User-Facing Changes (None now, end goal more explicit and consistent error messages) # Tests + Formatting (No additional tests needed so far)
This commit is contained in:
committed by
GitHub
parent
0a1af85200
commit
438062d7fc
@@ -193,13 +193,12 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { .. } => input.clone(),
|
||||
other => Value::Error {
|
||||
error: ShellError::OnlySupportsThisInputType(
|
||||
"int, filesize, float, string".into(),
|
||||
other.get_type().to_string(),
|
||||
span,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
),
|
||||
error: ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "int, filesize, float, string".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -87,13 +87,12 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { .. } => input.clone(),
|
||||
other => Value::Error {
|
||||
error: ShellError::OnlySupportsThisInputType(
|
||||
"integer or filesize".into(),
|
||||
other.get_type().to_string(),
|
||||
span,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
),
|
||||
error: ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "integer or filesize".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -188,13 +188,13 @@ pub fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { .. } => input.clone(),
|
||||
other => Value::Error {
|
||||
error: ShellError::OnlySupportsThisInputType(
|
||||
"integer, float, filesize, string, date, duration, binary or bool".into(),
|
||||
other.get_type().to_string(),
|
||||
span,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
),
|
||||
error: ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "integer, float, filesize, string, date, duration, binary or bool"
|
||||
.into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -166,13 +166,12 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { .. } => input.clone(),
|
||||
other => Value::Error {
|
||||
error: ShellError::OnlySupportsThisInputType(
|
||||
"bool, integer, float or string".into(),
|
||||
other.get_type().to_string(),
|
||||
span,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
),
|
||||
error: ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "bool, integer, float or string".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -213,13 +213,12 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
Value::Error { .. } => return input.clone(),
|
||||
other => {
|
||||
return Value::Error {
|
||||
error: ShellError::OnlySupportsThisInputType(
|
||||
"string and integer".into(),
|
||||
other.get_type().to_string(),
|
||||
head,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
),
|
||||
error: ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string and integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -332,13 +331,12 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { .. } => input.clone(),
|
||||
other => Value::Error {
|
||||
error: ShellError::OnlySupportsThisInputType(
|
||||
"string".into(),
|
||||
other.get_type().to_string(),
|
||||
head,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
),
|
||||
error: ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -108,13 +108,12 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, head: Span) -> Value {
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { .. } => input.clone(),
|
||||
other => Value::Error {
|
||||
error: ShellError::OnlySupportsThisInputType(
|
||||
"string, integer or bool".into(),
|
||||
other.get_type().to_string(),
|
||||
head,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
),
|
||||
error: ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string, integer or bool".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -486,13 +486,12 @@ fn action(
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { .. } => input.clone(),
|
||||
other => Value::Error {
|
||||
error: ShellError::OnlySupportsThisInputType(
|
||||
"string or duration".into(),
|
||||
other.get_type().to_string(),
|
||||
span,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
),
|
||||
error: ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string or duration".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -117,12 +117,12 @@ pub fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
||||
span: value_span,
|
||||
},
|
||||
other => Value::Error {
|
||||
error: ShellError::OnlySupportsThisInputType(
|
||||
"string and integer".into(),
|
||||
other.get_type().to_string(),
|
||||
span,
|
||||
value_span,
|
||||
),
|
||||
error: ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string and integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: value_span,
|
||||
},
|
||||
},
|
||||
}
|
||||
} else {
|
||||
|
@@ -246,13 +246,13 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { .. } => input.clone(),
|
||||
other => Value::Error {
|
||||
error: ShellError::OnlySupportsThisInputType(
|
||||
"integer, float, filesize, date, string, binary, duration or bool".into(),
|
||||
other.get_type().to_string(),
|
||||
span,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
),
|
||||
error: ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "integer, float, filesize, date, string, binary, duration or bool"
|
||||
.into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: span,
|
||||
src_span: other.expect_span(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -293,13 +293,12 @@ fn convert_int(input: &Value, head: Span, radix: u32) -> Value {
|
||||
Value::Error { .. } => return input.clone(),
|
||||
other => {
|
||||
return Value::Error {
|
||||
error: ShellError::OnlySupportsThisInputType(
|
||||
"string and integer".into(),
|
||||
other.get_type().to_string(),
|
||||
head,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
),
|
||||
error: ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string and integer".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.expect_span(),
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
@@ -185,13 +185,12 @@ fn into_record(
|
||||
Value::Record { cols, vals, span } => Value::Record { cols, vals, span },
|
||||
Value::Error { .. } => input,
|
||||
other => Value::Error {
|
||||
error: ShellError::OnlySupportsThisInputType(
|
||||
"string".into(),
|
||||
other.get_type().to_string(),
|
||||
call.head,
|
||||
// This line requires the Value::Error match above.
|
||||
other.expect_span(),
|
||||
),
|
||||
error: ShellError::OnlySupportsThisInputType {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: call.head,
|
||||
src_span: other.expect_span(),
|
||||
},
|
||||
},
|
||||
};
|
||||
Ok(res.into_pipeline_data())
|
||||
|
Reference in New Issue
Block a user