mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 22:37:45 +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
@ -1996,11 +1996,7 @@ impl Value {
|
||||
if let Some(val) = lhs.checked_add(*rhs) {
|
||||
Ok(Value::Int { val, span })
|
||||
} else {
|
||||
Err(ShellError::OperatorOverflow(
|
||||
"add operation overflowed".into(),
|
||||
span,
|
||||
"Consider using floating point values for increased range by promoting operand with 'into decimal'. Note: float has reduced precision!".into()
|
||||
))
|
||||
Err(ShellError::OperatorOverflow { msg: "add operation overflowed".into(), span, help: "Consider using floating point values for increased range by promoting operand with 'into decimal'. Note: float has reduced precision!".into() })
|
||||
}
|
||||
}
|
||||
(Value::Int { val: lhs, .. }, Value::Float { val: rhs, .. }) => Ok(Value::Float {
|
||||
@ -2023,33 +2019,33 @@ impl Value {
|
||||
if let Some(val) = lhs.checked_add_signed(chrono::Duration::nanoseconds(*rhs)) {
|
||||
Ok(Value::Date { val, span })
|
||||
} else {
|
||||
Err(ShellError::OperatorOverflow(
|
||||
"addition operation overflowed".into(),
|
||||
Err(ShellError::OperatorOverflow {
|
||||
msg: "addition operation overflowed".into(),
|
||||
span,
|
||||
"".into(),
|
||||
))
|
||||
help: "".into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
(Value::Duration { val: lhs, .. }, Value::Duration { val: rhs, .. }) => {
|
||||
if let Some(val) = lhs.checked_add(*rhs) {
|
||||
Ok(Value::Duration { val, span })
|
||||
} else {
|
||||
Err(ShellError::OperatorOverflow(
|
||||
"add operation overflowed".into(),
|
||||
Err(ShellError::OperatorOverflow {
|
||||
msg: "add operation overflowed".into(),
|
||||
span,
|
||||
"".into(),
|
||||
))
|
||||
help: "".into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
(Value::Filesize { val: lhs, .. }, Value::Filesize { val: rhs, .. }) => {
|
||||
if let Some(val) = lhs.checked_add(*rhs) {
|
||||
Ok(Value::Filesize { val, span })
|
||||
} else {
|
||||
Err(ShellError::OperatorOverflow(
|
||||
"add operation overflowed".into(),
|
||||
Err(ShellError::OperatorOverflow {
|
||||
msg: "add operation overflowed".into(),
|
||||
span,
|
||||
"".into(),
|
||||
))
|
||||
help: "".into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -2110,11 +2106,7 @@ impl Value {
|
||||
if let Some(val) = lhs.checked_sub(*rhs) {
|
||||
Ok(Value::Int { val, span })
|
||||
} else {
|
||||
Err(ShellError::OperatorOverflow(
|
||||
"subtraction operation overflowed".into(),
|
||||
span,
|
||||
"Consider using floating point values for increased range by promoting operand with 'into decimal'. Note: float has reduced precision!".into()
|
||||
))
|
||||
Err(ShellError::OperatorOverflow { msg: "subtraction operation overflowed".into(), span, help: "Consider using floating point values for increased range by promoting operand with 'into decimal'. Note: float has reduced precision!".into() })
|
||||
}
|
||||
}
|
||||
(Value::Int { val: lhs, .. }, Value::Float { val: rhs, .. }) => Ok(Value::Float {
|
||||
@ -2135,43 +2127,43 @@ impl Value {
|
||||
if let Some(v) = result.num_nanoseconds() {
|
||||
Ok(Value::Duration { val: v, span })
|
||||
} else {
|
||||
Err(ShellError::OperatorOverflow(
|
||||
"subtraction operation overflowed".into(),
|
||||
Err(ShellError::OperatorOverflow {
|
||||
msg: "subtraction operation overflowed".into(),
|
||||
span,
|
||||
"".into(),
|
||||
))
|
||||
help: "".into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
(Value::Date { val: lhs, .. }, Value::Duration { val: rhs, .. }) => {
|
||||
match lhs.checked_sub_signed(chrono::Duration::nanoseconds(*rhs)) {
|
||||
Some(val) => Ok(Value::Date { val, span }),
|
||||
_ => Err(ShellError::OperatorOverflow(
|
||||
"subtraction operation overflowed".into(),
|
||||
_ => Err(ShellError::OperatorOverflow {
|
||||
msg: "subtraction operation overflowed".into(),
|
||||
span,
|
||||
"".into(),
|
||||
)),
|
||||
help: "".into(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
(Value::Duration { val: lhs, .. }, Value::Duration { val: rhs, .. }) => {
|
||||
if let Some(val) = lhs.checked_sub(*rhs) {
|
||||
Ok(Value::Duration { val, span })
|
||||
} else {
|
||||
Err(ShellError::OperatorOverflow(
|
||||
"subtraction operation overflowed".into(),
|
||||
Err(ShellError::OperatorOverflow {
|
||||
msg: "subtraction operation overflowed".into(),
|
||||
span,
|
||||
"".into(),
|
||||
))
|
||||
help: "".into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
(Value::Filesize { val: lhs, .. }, Value::Filesize { val: rhs, .. }) => {
|
||||
if let Some(val) = lhs.checked_sub(*rhs) {
|
||||
Ok(Value::Filesize { val, span })
|
||||
} else {
|
||||
Err(ShellError::OperatorOverflow(
|
||||
"add operation overflowed".into(),
|
||||
Err(ShellError::OperatorOverflow {
|
||||
msg: "add operation overflowed".into(),
|
||||
span,
|
||||
"".into(),
|
||||
))
|
||||
help: "".into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -2195,11 +2187,7 @@ impl Value {
|
||||
if let Some(val) = lhs.checked_mul(*rhs) {
|
||||
Ok(Value::Int { val, span })
|
||||
} else {
|
||||
Err(ShellError::OperatorOverflow(
|
||||
"multiply operation overflowed".into(),
|
||||
span,
|
||||
"Consider using floating point values for increased range by promoting operand with 'into decimal'. Note: float has reduced precision!".into()
|
||||
))
|
||||
Err(ShellError::OperatorOverflow { msg: "multiply operation overflowed".into(), span, help: "Consider using floating point values for increased range by promoting operand with 'into decimal'. Note: float has reduced precision!".into() })
|
||||
}
|
||||
}
|
||||
(Value::Int { val: lhs, .. }, Value::Float { val: rhs, .. }) => Ok(Value::Float {
|
||||
@ -3192,11 +3180,7 @@ impl Value {
|
||||
if let Some(val) = lhs.checked_pow(*rhs as u32) {
|
||||
Ok(Value::Int { val, span })
|
||||
} else {
|
||||
Err(ShellError::OperatorOverflow(
|
||||
"pow operation overflowed".into(),
|
||||
span,
|
||||
"Consider using floating point values for increased range by promoting operand with 'into decimal'. Note: float has reduced precision!".into()
|
||||
))
|
||||
Err(ShellError::OperatorOverflow { msg: "pow operation overflowed".into(), span, help: "Consider using floating point values for increased range by promoting operand with 'into decimal'. Note: float has reduced precision!".into() })
|
||||
}
|
||||
}
|
||||
(Value::Int { val: lhs, .. }, Value::Float { val: rhs, .. }) => Ok(Value::Float {
|
||||
|
Reference in New Issue
Block a user