nushell/crates/nu-command
Antoine Stevan 05ff7a9925
FIX: do not allow *start > end* in error make spans (#8570)
This should close #8567.

# Description
this PR throws an error when `start > end` in the most complete branch
of `ErrorMake::run`, i.e. when `$.msg`, `$.label.text`, `$.label.start`
and `$.label.end` are defined.

i've also added a `error_start_bigger_than_end_should_fail` test to
check that it does indeed return the right error.

# User-Facing Changes
no more crash when manipulating span bounds and a clear error, e.g.
```bash
>_ error make {msg: "msg" label: {text: "text" start: 1010 end: 1000}}
Error:
  × invalid error format.
   ╭─[entry #3:1:1]
 1 │ error make {msg: "msg" label: {text: "text" start: 1010 end: 1000}}
   ·                               ──────────────────┬─────────────────
   ·                                                 ╰── `$.label.start` is stricly bigger than `$.label.end`
   ╰────
  help: 1010 > 1000
```
or
```bash
>_ error make {
:::     msg: "msg"
:::     label: {
:::         text: "text"
:::         start: ($nu.scope.engine_state.source_bytes - 90)
:::         end: ($nu.scope.engine_state.source_bytes - 100)
:::     }
::: }
Error:
  × invalid error format.
   ╭─[entry #4:2:1]
 2 │         msg: "msg"
 3 │ ╭─▶     label: {
 4 │ │           text: "text"
 5 │ │           start: ($nu.scope.engine_state.source_bytes - 90)
 6 │ │           end: ($nu.scope.engine_state.source_bytes - 100)
 7 │ ├─▶     }
   · ╰──── `$.label.start` is stricly bigger than `$.label.end`
 8 │     }
   ╰────
  help: 204525 > 204515
```

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🔴 `toolkit test`

# After Submitting
```
$nothing
```
2023-03-23 20:31:06 +01:00
..
assets refactor html module (#5246) 2022-04-20 08:50:14 -05:00
proptest-regressions/format_conversions Add proptest regression (#8396) 2023-03-15 20:08:02 -07:00
src Better error message for mv when file not found (#8586) 2023-03-23 11:31:49 -07:00
tests FIX: do not allow *start > end* in error make spans (#8570) 2023-03-23 20:31:06 +01:00
Cargo.toml Bump alphanumeric-sort from 1.4.4 to 1.5.0 (#8532) 2023-03-22 13:02:45 +00:00
LICENSE Include license text in all crates (#5094) 2022-04-08 10:47:13 +02:00