mirror of
https://github.com/nushell/nushell
synced 2025-01-15 22:54:16 +00:00
Add help text to concat eror message
This commit is contained in:
parent
bb8aaf6c6f
commit
9f3b5244f5
1 changed files with 40 additions and 9 deletions
|
@ -3165,18 +3165,49 @@ impl Value {
|
||||||
(Value::Custom { val: lhs, .. }, rhs) => {
|
(Value::Custom { val: lhs, .. }, rhs) => {
|
||||||
lhs.operation(self.span(), Operator::Math(Math::Concatenate), op, rhs)
|
lhs.operation(self.span(), Operator::Math(Math::Concatenate), op, rhs)
|
||||||
}
|
}
|
||||||
_ => Err(operator_type_error(
|
_ => {
|
||||||
Operator::Math(Math::Concatenate),
|
let help = if matches!(self, Value::List { .. })
|
||||||
op,
|
|| matches!(rhs, Value::List { .. })
|
||||||
self,
|
{
|
||||||
rhs,
|
Some("if you meant to append a value to a list or a record to a table, use the `append` command or wrap the value in a list. For example: `$list ++ $value` should be `$list ++ [$value]` or `$list | append $value`.")
|
||||||
|val| {
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let is_supported = |val: &Value| {
|
||||||
matches!(
|
matches!(
|
||||||
val,
|
val,
|
||||||
Value::List { .. } | Value::String { .. } | Value::Binary { .. },
|
Value::List { .. }
|
||||||
|
| Value::String { .. }
|
||||||
|
| Value::Binary { .. }
|
||||||
|
| Value::Custom { .. }
|
||||||
)
|
)
|
||||||
},
|
};
|
||||||
)),
|
Err(match (is_supported(self), is_supported(rhs)) {
|
||||||
|
(true, true) => ShellError::OperatorIncompatibleTypes {
|
||||||
|
op: Operator::Math(Math::Concatenate),
|
||||||
|
lhs: self.get_type(),
|
||||||
|
rhs: rhs.get_type(),
|
||||||
|
op_span: op,
|
||||||
|
lhs_span: self.span(),
|
||||||
|
rhs_span: rhs.span(),
|
||||||
|
help,
|
||||||
|
},
|
||||||
|
(true, false) => ShellError::OperatorUnsupportedType {
|
||||||
|
op: Operator::Math(Math::Concatenate),
|
||||||
|
unsupported: rhs.get_type(),
|
||||||
|
op_span: op,
|
||||||
|
unsupported_span: rhs.span(),
|
||||||
|
help,
|
||||||
|
},
|
||||||
|
(false, _) => ShellError::OperatorUnsupportedType {
|
||||||
|
op: Operator::Math(Math::Concatenate),
|
||||||
|
unsupported: self.get_type(),
|
||||||
|
op_span: op,
|
||||||
|
unsupported_span: self.span(),
|
||||||
|
help,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue