Create errors from tables. (#3986)

```
> [
  [          msg,                 labels,                      span];
  ["The message", "Helpful message here", ([[start, end]; [0, 141]])]
] | error make

error: The message
  ┌─ shell:1:1
  │
1 │ ╭ [
2 │ │   [          msg,                 labels,                      span];
3 │ │   ["The message", "Helpful message here", ([[start, end]; [0, 141]])]
  │ ╰─────────────────────────────────────────────────────────────────────^ Helpful message here
```

Adding a more flexible approach for creating error values. One use case, for instance is the
idea of a test framework. A failed assertion instead of printing to the screen it could create
tables with more details of the failed assertion and pass it to this command for making a full
fledge error that Nu can show. This can (and should) be extended for capturing error values as well
in the pipeline. One could also use it for inspection.

For example: `.... | error inspect { # inspection here }`

or "error handling" as well, like so: `.... | error capture { fix here }`

However, we start here only with `error make` that creates an error value for you with limited support for the time being.
This commit is contained in:
Andrés N. Robalino
2021-09-02 21:07:26 -05:00
committed by GitHub
parent d90420ac4c
commit c9c6bd4836
7 changed files with 156 additions and 21 deletions

View File

@ -79,6 +79,7 @@ fn tags_dont_persist_through_column_path() {
cd temp;
let x = (open ../nu_times.csv).name;
$x | tags | get anchor | autoview;
cd ..;
rmdir temp
"#
));
@ -105,7 +106,8 @@ fn tags_persist_through_vars() {
mkdir temp;
cd temp;
let x = (open ../nu_times.csv);
$x | tags | get anchor | autoview;
$x | tags | get anchor.file | autoview;
cd ..;
rmdir temp
"#
));