1514b9fbef
# Description Fixes: #13189 The issue is caused `error make` returns a `Value::Errror`, and when nushell pass it to `table -e` in `std help`, it directly stop and render the error message. To solve it, I think it's safe to make these examples return None directly, it doesn't change the reult of `help error make`. # User-Facing Changes ## Before ```nushell ~> help "error make" Error: nu:🐚:eval_block_with_input × Eval block failed with pipeline input ╭─[NU_STDLIB_VIRTUAL_DIR/std/help.nu:692:21] 691 │ ] { 692 │ let commands = (scope commands | sort-by name) · ───────┬────── · ╰── source value 693 │ ╰──── Error: × my custom error message ``` ## After ```nushell Create an error. Search terms: panic, crash, throw Category: core This command: - does not create a scope. - is a built-in command. - is a subcommand. - is not part of a plugin. - is not a custom command. - is not a keyword. Usage: > error make {flags} <error_struct> Flags: -u, --unspanned - remove the origin label from the error -h, --help - Display the help message for this command Signatures: <nothing> | error make[ <record>] -> <any> Parameters: error_struct: <record> The error to create. Examples: Create a simple custom error > error make {msg: "my custom error message"} Create a more complex custom error > error make { msg: "my custom error message" label: { text: "my custom label text" # not mandatory unless $.label exists # optional span: { # if $.label.span exists, both start and end must be present start: 123 end: 456 } } help: "A help string, suggesting a fix to the user" # optional } Create a custom error for a custom command that shows the span of the argument > def foo [x] { error make { msg: "this is fishy" label: { text: "fish right here" span: (metadata $x).span } } } ``` # Tests + Formatting Added 1 test |
||
---|---|---|
.. | ||
src | ||
std | ||
tests | ||
Cargo.toml | ||
CONTRIBUTING.md | ||
LICENSE | ||
README.md | ||
testing.nu |
Welcome to the standard library of `nushell`!
The standard library is a pure-nushell
collection of custom commands which
provide interactive utilities and building blocks for users writing casual scripts or complex applications.
To see what's here:
> use std
> scope commands | select name usage | where name =~ "std "
#┬───────────name────────────┬──────────────────────usage──────────────────────
0│std assert │Universal assert command
1│std assert equal │Assert $left == $right
2│std assert error │Assert that executing the code generates an error
3│std assert greater │Assert $left > $right
4│std assert greater or equal│Assert $left >= $right
... ...
─┴───────────────────────────┴─────────────────────────────────────────────────
🧰 Using the standard library in the REPL or in scripts
All commands in the standard library must be "imported" into the running environment
(the interactive read-execute-print-loop (REPL) or a .nu
script) using the
use
command.
You can choose to import the whole module, but then must refer to individual commands with a std
prefix, e.g:
use std
std log debug "Running now"
std assert (1 == 2)
Or you can enumerate the specific commands you want to import and invoke them without the std
prefix.
use std ["log debug" assert]
log debug "Running again"
assert (2 == 1)
This is probably the form of import you'll want to add to your env.nu
for interactive use.
✏️ contribute to the standard library
You're invited to contribute to the standard library! See CONTRIBUTING.md for details