nushell/crates/nu-std/std
Ian Manske 62e56d3581
Rework operator type errors (#14429)
# Description

This PR adds two new `ParseError` and `ShellError` cases for type errors
relating to operators.
- `OperatorUnsupportedType` is used when a type is not supported by an
operator in any way, shape, or form. E.g., `+` does not support `bool`.
- `OperatorIncompatibleTypes` is used when a operator is used with types
it supports, but the combination of types provided cannot be used
together. E.g., `filesize + duration` is not a valid combination.

The other preexisting error cases related to operators have been removed
and replaced with the new ones above. Namely:

- `ShellError::OperatorMismatch`
- `ShellError::UnsupportedOperator`
- `ParseError::UnsupportedOperationLHS`
- `ParseError::UnsupportedOperationRHS`
- `ParseError::UnsupportedOperationTernary`

# User-Facing Changes

- `help operators` now lists the precedence of `not` as 55 instead of 0
(above the other boolean operators). Fixes #13675.
- `math median` and `math mode` now ignore NaN values so that `[NaN NaN]
| math median` and `[NaN NaN] | math mode` no longer trigger a type
error. Instead, it's now an empty input error. Fixing this in earnest
can be left for a future PR.
- Comparisons with `nan` now return false instead of causing an error.
E.g., `1 == nan` is now `false`.
- All the operator type errors have been standardized and reworked. In
particular, they can now have a help message, which is currently used
for types errors relating to `++`.

```nu
[1] ++ 2
```
```
Error: nu::parser::operator_unsupported_type

  × The '++' operator does not work on values of type 'int'.
   ╭─[entry #1:1:5]
 1 │ [1] ++ 2
   ·     ─┬ ┬
   ·      │ ╰── int
   ·      ╰── does not support 'int'
   ╰────
  help: 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`.
```
2025-02-12 20:03:40 -08:00
..
assert Custom command attributes (#14906) 2025-02-11 06:34:51 -06:00
bench Custom command attributes (#14906) 2025-02-11 06:34:51 -06:00
config Remove unused FlatShapes And/Or (#14476) 2024-11-29 22:23:40 +01:00
dirs feat(std/dirs): retain state in subshells or with exec-restarts (#15080) 2025-02-11 19:51:43 -05:00
dt Custom command attributes (#14906) 2025-02-11 06:34:51 -06:00
formats fix multiline strings in NDNUON (#14519) 2024-12-05 07:53:33 -06:00
help Rework operator type errors (#14429) 2025-02-12 20:03:40 -08:00
input Fix usages of fmt to format number (#15041) 2025-02-07 23:50:33 +01:00
iter Custom command attributes (#14906) 2025-02-11 06:34:51 -06:00
log small, backwards compatible enhancements to std (#14763) 2025-01-06 11:30:07 -06:00
math Virtual std module subdirectories (#14040) 2024-10-10 06:56:37 -05:00
prelude Use build_target information in startup banner (#15046) 2025-02-07 12:10:13 -06:00
testing Custom command attributes (#14906) 2025-02-11 06:34:51 -06:00
util Custom command attributes (#14906) 2025-02-11 06:34:51 -06:00
xml Virtual std module subdirectories (#14040) 2024-10-10 06:56:37 -05:00
mod.nu Custom command attributes (#14906) 2025-02-11 06:34:51 -06:00