## Description
This PR fixes a bug where `"#00abcd"` couldn't be passed as a parameter
because `#` indicates to nushell that a comment is following.
## User-facing changes (Release notes)
Quotes strings with `"#"` in them like `"#00abcd"` are now allowed to be
passed as parameters.
### Example
A script named test.nu
```nushell
def main [color: string] {
$"Your color is ($color)"
}
```
Then pass a hex color as a parameter.
```nushell
❯ let myColor = "#000000"
❯ nu test.nu $myColor
Your color is #000000
❯ nu test.nu "#abcdef"
Your color is #abcdef
```
## Additional notes
closes https://github.com/nushell/nushell/issues/18778
<!--
Thanks for contributing to Nushell!
Before submitting, please read the contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md
This template helps reviewers understand your changes and allows us to
generate high-quality release notes.
-->
## Description
<!--
Explain what this PR does and why.
This section is intentionally flexible:
- Describe the problem
- Explain your approach
- Include technical details if relevant
Good examples:
- "In this PR, I fixed..."
- "In this PR, I added support for..."
- "This change improves X by..."
Write as much or as little as needed for reviewers to understand your
changes.
-->
Well, another batch of updated tests.
## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/
Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.
Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."
If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar
This tells us the change should not appear in the changelog.
Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise
You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure
Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."
You may leave this blank until the PR is ready.
-->
n/a
## Description
This PR fixes a problem when a script or REPL input used `source` to run
a `.nu` file, variables defined before the `source` call could become
invisible inside the sourced file, producing a "variable not found"
error.
Two distinct mechanisms contributed to the bug:
1. Double-parse in `evaluate_file`. The first parse stored blocks from
`source` with one set of `VarId`s. The second prase created _new_
`VarId`s for `let`/`mut` declarations. The `source` results were cached
but referenced the old `VarId`s.
2. Cross-session block caching in the parser -
`find_block_by_span(new_span)` in `parse_captures_compile` was called to
avoid re-parsing files that had already been parsed. This cached data
was stored in the permanent state. In the repl, if `let xxx` was
redeclared (getting a new varid), the cached block was used referencing
the old varid.
## User-facing changes (Release notes)
Fixes the bugs found when a script or REPL input used `source` to run a
`.nu` file, variables defined before the `source` call could become
invisible inside the sourced file, producing a "variable not found"
error.
**Example reproducing the bug** — script file `lll.nu`:
```nushell
let xxx = 'let in script'
source sss.nu
```
Where `sss.nu` contains:
```nushell
print $xxx
```
Running `nu lll.nu` would fail with:
```nushell
Error: nu::shell::variable_not_found
× Variable not found
╭─[sss.nu:1:7]
1 │ print $xxx
· ──┬─
· ╰── variable not found
╰────
```
The same error could also appear in the REPL after re-declaring a
variable:
```nushell
❯ let xxx = 'value 1'
❯ source sss.nu # OK: prints "value 1"
❯ let xxx = 'value 2'
❯ source sss.nu # Error: variable not found
```
After this change the last statement above would print `value 2`. See
the tests and the issue to see more variations.
## Additional notes
closes https://github.com/nushell/nushell/issues/18515
<!--
Thanks for contributing to Nushell!
Before submitting, please read the contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md
This template helps reviewers understand your changes and allows us to
generate high-quality release notes.
-->
## Description
<!--
Explain what this PR does and why.
This section is intentionally flexible:
- Describe the problem
- Explain your approach
- Include technical details if relevant
Good examples:
- "In this PR, I fixed..."
- "In this PR, I added support for..."
- "This change improves X by..."
Write as much or as little as needed for reviewers to understand your
changes.
-->
This PR updates the internal commands tests. This is, next to #18717,
also a very large file. So it got separated into its own PR too.
## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/
Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.
Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."
If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar
This tells us the change should not appear in the changelog.
Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise
You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure
Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."
You may leave this blank until the PR is ready.
-->
n/a
---
<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
<!--
Thanks for contributing to Nushell!
Before submitting, please read the contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md
This template helps reviewers understand your changes and allows us to
generate high-quality release notes.
-->
## Description
<!--
Explain what this PR does and why.
This section is intentionally flexible:
- Describe the problem
- Explain your approach
- Include technical details if relevant
Good examples:
- "In this PR, I fixed..."
- "In this PR, I added support for..."
- "This change improves X by..."
Write as much or as little as needed for reviewers to understand your
changes.
-->
This PR updates the external commands tests. This file is pretty large
and therefore separated into its own PR.
## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/
Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.
Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."
If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar
This tells us the change should not appear in the changelog.
Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise
You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure
Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."
You may leave this blank until the PR is ready.
-->
n/a
---
<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
<!--
Thanks for contributing to Nushell!
Before submitting, please read the contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md
This template helps reviewers understand your changes and allows us to
generate high-quality release notes.
-->
## Description
<!--
Explain what this PR does and why.
This section is intentionally flexible:
- Describe the problem
- Explain your approach
- Include technical details if relevant
Good examples:
- "In this PR, I fixed..."
- "In this PR, I added support for..."
- "This change improves X by..."
Write as much or as little as needed for reviewers to understand your
changes.
-->
`nu --testbin` is going to be removed by #18719, so this PR starts by
refactoring all tests that call `nu --testbin` in some way. Not only are
these tests refactored but then the whole file. Instead of calling `nu
--testbin`, the relevant `#[deps(TESTBIN_x)]` is annotated on the test
and the test binary is called directly.
The files in this PR are the smaller ones, the larges ones are in
seperate PRs up the stack.
## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/
Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.
Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."
If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar
This tells us the change should not appear in the changelog.
Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise
You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure
Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."
You may leave this blank until the PR is ready.
-->
n/a
---
<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
<!--
Thanks for contributing to Nushell!
Before submitting, please read the contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md
This template helps reviewers understand your changes and allows us to
generate high-quality release notes.
-->
## Description
<!--
Explain what this PR does and why.
This section is intentionally flexible:
- Describe the problem
- Explain your approach
- Include technical details if relevant
Good examples:
- "In this PR, I fixed..."
- "In this PR, I added support for..."
- "This change improves X by..."
Write as much or as little as needed for reviewers to understand your
changes.
-->
This PR updates some more test to the new harness by replacing
`nu_repl_code` and `nu!`.
This set of tests is grouped together, as they did use `nu_repl_code` in
some capacity. After this PR no more `nu_repl_code` should be used
anywhere.
## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/
Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.
Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."
If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar
This tells us the change should not appear in the changelog.
Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise
You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure
Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."
You may leave this blank until the PR is ready.
-->
n/a
---
<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
## Description
- Enabled `pretty_assertions`'s `unstable` feature to get
`assert_matches!` (the stdlib version is available in 1.96)
- Tried to keep most tests 1:1, though I made some significant changes
here and there.
## User-facing changes (Release notes)
N/A
---------
Co-authored-by: Tim 'Piepmatz' Hesse <git+github@cptpiepmatz.de>
## Description
- #16832
Errors raised for assignment errors did not point to the relevant
assignment, just pointed to the values origin.
## User-facing changes (Release notes)
### More helpful errors for failed assignments with
`enforce-runtime-annotations`
With `enforce-runtime-annotations` enabled, assignments with incorrect
types raise errors.
Previously this error was `nu::shell::cant_convert` originally used for
unsuccessful type coercions of command arguments. Unfortunately, this
error only pointed at the assigned values *origin* and not at the failed
assignment.
This error has been switched to `nu::shell::type_mismatch` and now
points to the failed assignment in addition to the value's origin.
##### example 1
<table>
<tr>
<td>Code</td>
<td width="1000">
```nushell
mut execution_time = -1
$execution_time = $env.CMD_DURATION_MS
```
</td>
</tr>
<tr>
<td>Before</td>
<td>
```
Error: nu::shell::cant_convert
× Can't convert to int.
╭─[Host Environment Variables:1:1]
1 │ "LANG"="en_US.UTF-8"
· ▲
· ╰── can't convert string to int
2 │ "LC_TIME"="en_DK.UTF-8"
╰────
```
</td>
</tr>
<tr>
<td>After</td>
<td>
```
Error: nu::shell::type_mismatch
× Type mismatch.
╭─[repl_entry #3:2:17]
1 │ mut execution_time = -1
2 │ $execution_time = $env.CMD_DURATION_MS
· ┬
· ╰── expected int, got string
╰────
```
</td>
</tr>
</table>
##### example 2
<table>
<tr>
<td>Code</td>
<td width="1000">
```nushell
# delibarete type erasure
# we need to bypass parse-time
# type checking for this example
let stuff: any = {
foo: "bar"
}
mut x = 1
$x = $stuff.foo
```
</td>
</tr>
<tr>
<td>Before</td>
<td>
```
Error: nu::shell::cant_convert
× Can't convert to int.
╭─[repl_entry #7:5:7]
4 │ let stuff: any = {
5 │ foo: "bar"
· ──┬──
· ╰── can't convert string to int
6 │ }
╰────
```
</td>
</tr>
<tr>
<td>After</td>
<td>
```
Error: nu::shell::type_mismatch
× Type mismatch.
╭─[repl_entry #1:5:7]
4 │ let stuff: any = {
5 │ foo: "bar"
· ──┬──
· ╰── the value is a string
6 │ }
7 │
8 │ mut x = 1
9 │
10 │ $x = $stuff.foo
· ┬
· ╰── expected int, got string
╰────
```
</td>
</tr>
</table>
## Additional notes
- This should make it much easier to diagnose problems described in
#18528
## Description
Removed the copy/paste command from stdlib that were deprecated in
`0.111.0`. I think it makes sense to remove these sooner rather than
later since it can be confusing that they have the exact same name as
the ones in the "new" `native-clip` experimental option.
## User-facing changes (Release notes)
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/
Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.
Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."
If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar
This tells us the change should not appear in the changelog.
Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise
You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure
Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."
You may leave this blank until the PR is ready.
-->
Removed the deprecated `use std/clip` `copy` and `paste` commands, they
are now called `copy52` and `paste52` for the ones that use the terminal
`OSC 52`, or you can use `clip copy` and `clip paste` from the
experimental option `native-clip` that access the system clipboard
directly.
<!--
Optional.
Examples:
- fixes#123
- closes#456
- related #789
Anything else reviewers should know.
Remove this section if not needed.
-->
## Description
Reading my config (which had some elaborate startup code) caused these
tests to fail. Likely because of `term query` calls.
## User-facing changes (Release notes)
N/A
## Additional notes
Tests being affected by user config is unfortunately a reoccurring
issue.
We should consider setting `XDG_{CONFIG,DATA,CACHE}_HOME` and
`XDG_DATA_DIRS` to empty directories during tests to avoid this problem
all together rather than patching it on a test by test basis.
<!--
Thanks for contributing to Nushell!
Before submitting, please read the contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md
This template helps reviewers understand your changes and allows us to
generate high-quality release notes.
-->
## Description
This PR improves repl error handling when being redirected.
<!--
Explain what this PR does and why.
This section is intentionally flexible:
- Describe the problem
- Explain your approach
- Include technical details if relevant
Good examples:
- "In this PR, I fixed..."
- "In this PR, I added support for..."
- "This change improves X by..."
Write as much or as little as needed for reviewers to understand your
changes.
-->
## User-facing changes (Release notes)
Improve repl error handling when redirected like `nu > /dev/full` or `nu
2>/dev/full`.
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/
Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.
Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."
If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar
This tells us the change should not appear in the changelog.
Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise
You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure
Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."
You may leave this blank until the PR is ready.
-->
## Additional notes
closes https://github.com/nushell/nushell/issues/18208
closes https://github.com/nushell/nushell/issues/18209
<!--
Optional.
Examples:
- fixes#123
- closes#456
- related #789
Anything else reviewers should know.
Remove this section if not needed.
-->
<!--
Thank you for improving Nushell!
Please, read our contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md
-->
This PR enables the clippy lint `needless_raw_strings` to avoid raw
strings where they aren't needed. We have a lot of them and I don't
think that's that nice tbh.
## Release notes summary - What our users need to know
<!--
This section will be included as part of our release notes. See the
contributing guide for more details.
Please include only details relevant for users here. Motivation and
technical details can be added above or below this section.
You may leave this section blank until your PR is finalized. Ask a core
team member if you need help filling this section.
-->
n/a
There are some edge cases when working with environment variables. So, I
took the opportunity in this PR to refactor how nushell handles env
vars. All environment variables across all operating systems and
case-insensitive for lookups and case-preserving for storage.
This is how it now works. All environment variable access goes through
EnvName in env_names.rs now, except for a few places that still need to
use `std::env::var()` type calls for initial nushell setup.
```
//! ## Case Sensitivity Rules
//!
//! - **All platforms**: All environment variable names are case-insensitive but case-preserving.
//! This means `PATH`, `Path`, and `path` refer to the same variable, and so do `HOME` and `home`.
//!
//! This ensures that:
//! - `$env.PATH`, `$env.path`, `$env.Path` all work on any platform
//! - `$env.HOME`, `$env.home` all refer to the same variable
//! - Case is preserved when storing the variable name
//! - Existing scripts may need updates if they relied on case sensitivity
```
## Release notes summary - What our users need to know
All environment variables across all operating systems and
case-insensitive for lookups and case-preserving for storage.
## Tasks after submitting
<!-- Remove any tasks which aren't relevant for your PR, or add your own
-->
- [ ] Update the
[documentation](https://github.com/nushell/nushell.github.io)
As title
It reveals somes issues, like breaking `do -i`. So this pr fixes it as
well.
I introduce a new type `ExitStatusGuard` which wraps both
`exit_stauts_future` and `ignore_error`. So we can check the status
easier.
## Release notes summary - What our users need to know
nushell will use `pipefail` by default, so something like `^false |
lines` returns an empty list, with a failure exit status code
## Tasks after submitting
NaN
## User-facing Changes
* New arguments! (`error make "hello"`)
* New parts for `error_struct`! (`error make {inner: [] labels: []
...}`)
* Pipeline inputs for chained errors! (`try {error make foo} catch
{error make bar}`)
* Pipeline inputs for normal errors! (`"help" | error make`)
* External errors! (`error make {src: {path: $nu.cofig-path} ...}`)
* Backwards compatibility!
### Arguments and Inputs
The main changes are in how the arguments are passed. Everything is
still backwards compatible with the old `error make` commands, there's
just a nice extra layer we get from the pipeline and a few new args
(that were already added in #17037). There are some new ways to
(hopefully intentionally) cause an error, such as using a naked `error
make`, pipelines from records and simple string input!
#### Inputs
Because `error make` will just make an error anyway, it can technically
take any input to make an error, but only properly formatted record
input will create a chain. the `x | f $in` pattern can be used for
string input, if that is more comfortable.
#### With no arguments
This is a completely new way to do this, with no arguments the `error
make` invocation is highlighted, along with a simple `originates from
here` message. This makes normal errors very easy to create without any
special message setup.
```
> error make
Error: nu::shell::error
× originates from here
╭─[entry #4:1:1]
1 │ error make
· ──────────
╰────
```
#### Create a single argument
* With pipeline input: `{msg: foo} | error make`
* With an argument: `error make {msg: foo}`
* With a string argument: `error make foo`
```
Error: nu::shell::error
× foo
╭─[entry #2:1:12]
1 │ error make {msg: foo}
· ──────────
╰────
```
#### Chaining errors together
These will automatically create a chain of errors, placing the pipeline
as an `inner` to the argument. This can very easily be used to get a bit
more detail in a try loop using the naked `error make`:
```
Error: nu::shell::error
× originates from here
╭─[source:1:31]
1 │ try {error make "foo"} catch {error make}
· ──────────
╰────
Error: nu::shell::error
× foo
╭─[source:1:6]
1 │ try {error make "foo"} catch {error make}
· ──────────
╰────
```
Or with more complex errors:
* With both, combining the errors: `{msg: foo} | error make bar`
* With the raw error from try: `try {error make foo} catch {error make
bar}`
Both are equivalent to:
* `error make {msg: bar inner: [{msg: foo}]}`
```
Error: nu::shell::error
× bar
╭─[entry #1:1:29]
1 │ try {error make foo} catch {error make bar}
· ──────────
╰────
Error: nu::shell::error
× foo
╭─[entry #1:1:6]
1 │ try {error make foo} catch {error make bar}
· ──────────
╰────
```
### Labels
As is noticeable in the examples above, simple errors no longer use an
extra line for the label. If no label is present, `error make` will
place a bar under the span of itself or the argument to `error make`.
Labels have also gotten a bit of a rewrite, but they're pretty much the
same as those in #17037, except for `label`, which is now only a single
label (not `oneof<list, label>`).
#### Simple Labels
`label.text` and `labels.*.text` is no longer required for a span to
show up, an empty text will simply underline. This example can either
use `label: $record` or be written as `labels: [$record]`:
```
> def f [x] {
error make {msg: here label: {span: (metadata $x).span}}
}
f abcd
Error: nu::shell::error
× here
╭─[entry #7:4:3]
3 │ }
4 │ f abcd
· ────
╰────
```
#### Multiple labels
Any number of labels can be added in the `labels` column, allowing for
more detailed error messages, especially for functions:
```
> def f [x y z] {
error make {msg: here labels: [
{text: "there" span: (metadata $x).span}
{text: "everywhere" span: (metadata $y).span}
{text: "somewhere" span: (metadata $z).span}
]
}
}
f abcd [x y z] {d: a}
Error: nu::shell::error
× here
╭─[entry #11:9:3]
8 │ }
9 │ f abcd [x y z] {d: a}
· ──┬─ ───┬─── ───┬──
· │ │ ╰── somewhere
· │ ╰── everywhere
· ╰── there
╰────
```
#### External sources
There is a `ShellError::OutsideSpannedLabeledError` that can be used to
refer to external sources, not just the internal nushell spanns. This
has been expanded to allow the multi-label stuff to work using the new
`src` column:
```
> "foo\nbar\nbaz" | save -f /tmp/foo.bar
error make {
msg: 'error here'
src: {path: /tmp/foo.bar}
labels: [
{text: "this" span: {start: 4 end: 7}}
]
}
Error: nu::shell::outside
× error here
╭─[/tmp/foo.bar:2:1]
1 │ foo
2 │ bar
· ─┬─
· ╰── this
3 │ baz
╰────
```
### Errors That Can't be Caught
These will not work since `try` will never get parsed:
- `try {1 + ""} catch {error make badmath}`
- (TODO: Add more examples)
## Internal Changes
Most of the parsing from an error record to an actual error is now moved
into `nu-protocol`, using `FromValue` to turn it into a useful internal
type.
### `nu-protocol::LabeledError`
This struct has a few changes, the main one being the type of
`LabeledError.inner`. It is now a `ShellError`, not another
`LabeledError`. It should be trivial to do a `.into()` for things that
already use `LabeledError.with_inner(x)`.
### `nu-protocol::ShellError::into_value`
I renamed the old `into_value` to `into_full_value` to better say what
it is, since it doesn't just do the `IntoValue::into_value` method, it
also requires some context to create the `Value`. Now `ShellError` has
an `IntoValue` implementation matching other types.
### `nu-protocol::ShellError::{OutsideSource, OutsideSourceNoUrl}`
Miette's derived types don't have a nice way to maybe include a url, so
there are now two types! These allow using multiple labels on outside
sources. They are used internally for the new `{src: {}}` part of the
`error_struct`, and they look a lot more like the `LabeledError`, but
without the need for a separate type and all the fun `impl`s that would
require for the `Diagnostic::source_code` method.
### Misc
* Spelling fix: `into_chainned` => `into_chained`
## Current bugs:
- [x] `OutsideSpannedLabeledError`
The inner most error of `try {']' from nuon} catch {error make}` will
reference `span: {start: 0, end: 1}`, which in `']' from nuon` will
point to the `]` character, but when it does this in `error make` as an
input it will point to the very first character (probably the `n` in
`nu`).
## Release notes summary - What our users need to know
### New `error make` functionality!
* New arguments! (`error make "hello"`)
* New parts for `error_struct`! (`error make {inner: [] labels: []
...}`)
* Pipeline inputs for chained errors! (`try {error make foo} catch
{error make bar}`)
* Pipeline inputs for normal errors! (`"help" | error make`)
* External errors! (`error make {src: {path: $nu.cofig-path} ...}`)
* Backwards compatibility!
## Tasks after submitting
<!-- Remove any tasks which aren't relevant for your PR, or add your own
-->
- [ ] Update the
[documentation](https://github.com/nushell/nushell.github.io)
Fixes: #14745
## Release notes summary - What our users need to know
If user runs script or command with a bad config file, the script or
command won't run.
```
echo 'errnocmd' | save config.nu
nu --config config.nu -c 'echo $env.NU_VERSION'
```
won't show nushell version and exits with status code 1.
Just uses `ends-with` and a prefix to skip the control characters at the
start of the strings
This fixes the issues that came up in #17038 for being run in terminals.
This doesn't fix the underlying issue, however it does allow tests to be
run in certain terminals and still pass.
This also fixes a problem with some of the tests that load `std/log`. If
`$env.NU_LOG_FORMAT` is set in the parent shell, then these tests will
incorrectly fail. Clearing the env out before running makes these work.
<!--
Thank you for improving Nushell!
Please, read our contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md
-->
## Release notes summary - What our users need to know
<!--
This section will be included as part of our release notes. See the
contributing guide for more details.
Please include only details relevant for users here. Motivation and
technical details can be added above or below this section.
You may leave this section blank until your PR is finalized. Ask a core
team member if you need help filling this section.
-->
## Tasks after submitting
<!-- Remove any tasks which aren't relevant for your PR, or add your own
-->
- [ ] Update the
[documentation](https://github.com/nushell/nushell.github.io)
This pr address comment by @132ikl :
https://github.com/nushell/nushell/issues/16760#issuecomment-3344409581
After visiting IR of `let x = ^false | into int`:
```
# 2 registers, 8 instructions, 5 bytes of data
0: load-literal %1, glob-pattern("false", no_expand = false)
1: push-positional %1
2: redirect-out pipe
3: call decl 142 "run-external", %0
4: redirect-out value
5: call decl 299 "into int", %0
6: store-variable var 320, %0 # let
7: return %0
```
Nushell runs `store-variable` instruction, which collect values from
registry through `collect_reg`. This pr adds `check_exit_status_future`
logic inside `collect_reg` to make pipefail works with `let`.
## Release notes summary - What our users need to know
### pipefail works well with `let`
```
let x = bash -c "echo 123; exit 1" | into int; $x
Error: nu::shell::non_zero_exit_code
× External command had a non-zero exit code
╭─[entry #28:1:9]
1 │ let x = bash -c "echo 123; exit 1" | into int; $x
· ──┬─
· ╰── exited with code 1
╰────
```
- refactored how `nu!` executes commands
- commands are no longer split into lines and joined with semicolons,
they are passed verbatim to nu
- removes the need for `pipeline()`
- **Removed built-in string formatting from `nu!`**. Going through almost
all uses of `nu!` across the code base it became clear that:
- built-in formatting is rarely used
- most people are not aware of it and use `format!` anyway
- it can't be used with `"{inline}"` arguments because it's only
activated if there are extra arguments after the nu code string
## Release notes summary - What our users need to know
N/A
## Tasks after submitting
N/A
Closes: #13817
The core requirement here is to have a way to track all exit status in a
pipeline. To achieve this without affecting command itself.
I created a new struct in `pipeline_data.rs`:
```rust
pub struct PipelineExecutionData {
pub body: PipelineData,
/// This field is using to track all exit status in a pipeline.
pub exit: Vec<Option<(Arc<Mutex<ExitStatusFuture>>, Span)>>,
}
```
Then I changed registers in `EvalContext` from `&'a mut [PipelineData]`
to `&'a mut [PipelineExecutionData]`. So the eval engine itself can
track exit status.
Then during evaluation, when nushell is going to execute
`Instruction::Call`. It takes `input.exit` first, then attach this into
`results.exit`. This is similar to the way nushell implements backtrace
feature.
After all of this, when nushell executes `Instruction::Drain`, or
printing pipeline. It iterates through *exit_futures* reversely. To see
if a command exits with non-zero status.
## Release notes summary - What our users need to know
This release will be add an experimental option for `pipefail`. This can
be set using `nu --experimental-options=['pipefail']`
> If set, the LAST_EXIT_CODE will be set to any command which exit with
a non-zero status, or zero if all commands in the pipeline exit
successfully.
```nushell
> ^false | print aa
aa
> $env.LAST_EXIT_CODE
1
```
It'd be more interesting if using it with
`$env.config.display_errors.exit_code = true`. Show users are able to
see which command is failed.
```nushell
> $env.config.display_errors.exit_code = true
> ^ls | ^false | print aa
aa
Error: nu::shell::non_zero_exit_code
× External command had a non-zero exit code
╭─[entry #5:1:8]
1 │ ^ls | ^false | print aa
· ──┬──
· ╰── exited with code 1
╰────
```
## Tasks after submitting
- [ ] Update the
[documentation](https://github.com/nushell/nushell.github.io)
---------
Co-authored-by: rose <132@ikl.sh>
# Description
Adds an `extern` definition (`KnownExternal`) for the `nu` command. This
way you can do `help nu` and get tab completions for flags on the `nu`
executable
# User-Facing Changes
* You can now view the flags for Nushell itself with `help nu`, and tab
completion for flags on `nu` works
# Description
Partially handles #14799
It's difficult to fix all cases there, but I think it's good to improve
one of this with a small step
# User-Facing Changes
Given the following code in c:
```C
// write.c
#include <stdio.h>
int main() {
while (1) {
printf("a\n");
}
}
```
After this pr, `./write | 0` will exit immediately, in that case,
`./write` will receive `SIGPIPE` in unix. Before this pr, `./write | 0`
runs indefinitely.
-----------------------
Maybe it's easier to see what happened internally by the different
output of `view ir { ./write | 0 }` command.
### Before
```
# 2 registers, 6 instructions, 7 bytes of data
0: load-literal %1, glob-pattern("./write", no_expand = false)
1: push-positional %1
2: redirect-out null
3: call decl 135 "run-external", %0
4: load-literal %0, int(0)
5: return %0
```
### After
```
# 2 registers, 6 instructions, 7 bytes of data
0: load-literal %1, glob-pattern("./write", no_expand = false)
1: push-positional %1
2: redirect-out pipe # changed, the command's output is a pipe rather than null
3: call decl 136 "run-external", %0
4: load-literal %0, int(0)
5: return %0
```
# Tests + Formatting
Added 1 test.
# After Submitting
NaN
- fixes#16011
# Description
`Display` implementation for `f64` omits the decimal part for round
numbers, and by using it we did the same.
This affected:
- conversions to delimited formats: `csv`, `tsv`
- textual formats: `html`, `md`, `text`
- pretty printed `json` (`--raw` was unaffected)
- how single float values are displayed in the REPL
> [!TIP]
> This PR fixes our existing json pretty printing implementation.
> We can likely switch to using serde_json's impl using its
PrettyFormatter which allows arbitrary indent strings.
# User-Facing Changes
- Round trips through `csv`, `tsv`, and `json` preserve the type of
round floats.
- It's always clear whether a number is an integer or a float in the
REPL
```nushell
4 / 2
# => 2 # before: is this an int or a float?
4 / 2
# => 2.0 # after: clearly a float
```
# Tests + Formatting
Adjusted tests for the new behavior.
- 🟢 toolkit fmt
- 🟢 toolkit clippy
- 🟢 toolkit test
- 🟢 toolkit test stdlib
# After Submitting
N/A
---------
Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
# Description
Fixes: #15510
I think it's introduced by #14653, which changes `and/or` to `match`
expression.
After looking into `compile_match`, it's important to collect the value
before matching this.
```rust
// Important to collect it first
builder.push(Instruction::Collect { src_dst: match_reg }.into_spanned(match_expr.span))?;
```
This pr is going to apply the logic while compiling `and/or` operation.
# User-Facing Changes
The following will raise a reasonable error:
```nushell
> (nu --testbin cococo false) and true
Error: nu::shell::operator_unsupported_type
× The 'and' operator does not work on values of type 'string'.
╭─[entry #7:1:2]
1 │ (nu --testbin cococo false) and true
· ─┬ ─┬─
· │ ╰── does not support 'string'
· ╰── string
╰────
```
# Tests + Formatting
Added 1 test.
# After Submitting
Maybe need to update doc
https://github.com/nushell/nushell.github.io/pull/1876
---------
Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
The `$env.SHLVL` tests, while improved, still cause CI (usually local)
an irritating percentage of the time. Until we can come with a better
way of testing, we're going to ignore them.
# 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`.
```
# Description
After this pr, nushell is able to raise errors with a backtrace, which
should make users easier to debug. To enable the feature, users need to
set env variable via `$env.NU_BACKTRACE = 1`. But yeah it might not work
perfectly, there are some corner cases which might not be handled.
I think it should close#13379 in another way.
### About the change
The implementation mostly contained with 2 parts:
1. introduce a new `ChainedError` struct as well as a new
`ShellError::ChainedError` variant. If `eval_instruction` returned an
error, it converts the error to `ShellError::ChainedError`.
`ChainedError` struct is responsable to display errors properly. It
needs to handle the following 2 cases:
- if we run a function which runs `error make` internally, it needs to
display the error itself along with caller span.
- if we run a `error make` directly, or some commands directly returns
an error, we just want nushell raise an error about `error make`.
2. Attach caller spans to `ListStream` and `ByteStream`, because they
are lazy streams, and *only* contains the span that runs it
directly(like `^false`, for example), so nushell needs to add all caller
spans to the stream.
For example: in `def a [] { ^false }; def b [] { a; 33 }; b`, when we
run `b`, which runs `a`, which runs `^false`, the `ByteStream` only
contains the span of `^false`, we need to make it contains the span of
`a`, so nushell is able to get all spans if something bad happened.
This behavior is happened after running `Instruction::Call`, if it
returns a `ByteStream` and `ListStream`, it will call `push_caller_span`
method to attach call spans.
# User-Facing Changes
It's better to demostrate how it works by examples, given the following
definition:
```nushell
> $env.NU_BACKTRACE = 1
> def a [x] { if $x == 3 { error make {msg: 'a custom error'}}}
> def a_2 [x] { if $x == 3 { ^false } else { $x } }
> def a_3 [x] { if $x == 3 { [1 2 3] | each {error make {msg: 'a custom error inside list stream'} } } }
> def b [--list-stream --external] {
if $external == true {
# error with non-zero exit code, which is generated from external command.
a_2 1; a_2 3; a_2 2
} else if $list_stream == true {
# error generated by list-stream
a_3 1; a_3 3; a_3 2
} else {
# error generated by command directly
a 1; a 2; a 3
}
}
```
Run `b` directly shows the following error:
<details>
```nushell
Error: chained_error
× oops
╭─[entry #27:1:1]
1 │ b
· ┬
· ╰── error happened when running this
╰────
Error: chained_error
× oops
╭─[entry #26:10:19]
9 │ # error generated by command directly
10 │ a 1; a 2; a 3
· ┬
· ╰── error happened when running this
11 │ }
╰────
Error:
× a custom error
╭─[entry #6:1:26]
1 │ def a [x] { if $x == 3 { error make {msg: 'a custom error'}}}
· ─────┬────
· ╰── originates from here
╰────
```
</details>
Run `b --list-stream` shows the following error
<details>
```nushell
Error: chained_error
× oops
╭─[entry #28:1:1]
1 │ b --list-stream
· ┬
· ╰── error happened when running this
╰────
Error: nu::shell::eval_block_with_input
× Eval block failed with pipeline input
╭─[entry #26:7:16]
6 │ # error generated by list-stream
7 │ a_3 1; a_3 3; a_3 2
· ─┬─
· ╰── source value
8 │ } else {
╰────
Error: nu::shell::eval_block_with_input
× Eval block failed with pipeline input
╭─[entry #23:1:29]
1 │ def a_3 [x] { if $x == 3 { [1 2 3] | each {error make {msg: 'a custom error inside list stream'} } } }
· ┬
· ╰── source value
╰────
Error:
× a custom error inside list stream
╭─[entry #23:1:44]
1 │ def a_3 [x] { if $x == 3 { [1 2 3] | each {error make {msg: 'a custom error inside list stream'} } } }
· ─────┬────
· ╰── originates from here
╰────
```
</details>
Run `b --external` shows the following error:
<details>
```nushell
Error: chained_error
× oops
╭─[entry #29:1:1]
1 │ b --external
· ┬
· ╰── error happened when running this
╰────
Error: nu::shell::eval_block_with_input
× Eval block failed with pipeline input
╭─[entry #26:4:16]
3 │ # error with non-zero exit code, which is generated from external command.
4 │ a_2 1; a_2 3; a_2 2
· ─┬─
· ╰── source value
5 │ } else if $list_stream == true {
╰────
Error: nu::shell::non_zero_exit_code
× External command had a non-zero exit code
╭─[entry #7:1:29]
1 │ def a_2 [x] { if $x == 3 { ^false } else { $x } }
· ──┬──
· ╰── exited with code 1
╰────
```
</details>
It also added a message to guide the usage of NU_BACKTRACE, see the last
line in the following example:
```shell
ls asdfasd
Error: nu::shell::io::not_found
× I/O error
╰─▶ × Entity not found
╭─[entry #17:1:4]
1 │ ls asdfasd
· ───┬───
· ╰── Entity not found
╰────
help: The error occurred at '/home/windsoilder/projects/nushell/asdfasd'
set the `NU_BACKTRACE=1` environment variable to display a backtrace.
```
# Tests + Formatting
Added some tests for the behavior.
# After Submitting
# Description
This is a follow up for pr:
https://github.com/nushell/nushell/pull/13873
In that pr, I left 2 TODOs about tests, this pr is going to resolve
them.
# User-Facing Changes
NaN
# Tests + Formatting
Added 2 tests
# Description
This PR cleans up the code surrounding formatting and displaying file
sizes.
- The `byte_unit` crate we use for file size units displays kilobytes as
`KB`, which is not the SI or ISO/IEC standard. Rather it should be `kB`,
so this fixes#8872. On some systems, `KB` actually means `KiB`, so this
avoids any potential confusion.
- The `byte_unit` crate, when displaying file sizes, casts integers to
floats which will lose precision for large file sizes. This PR adds a
custom `Display` implementation for `Filesize` that can give an exact
string representation of a `Filesize` for metric/SI units.
- This PR also removes the dependency on the `byte_unit` crate which
brought in several other dependencies.
Additionally, this PR makes some changes to the config for filesize
formatting (`$env.config.filesize`).
- The previous filesize config had the `metric` and `format` options. If
a metric (SI) unit was set in `format`, but `metric` was set to false,
then the `metric` option would take precedence and convert `format` to
the corresponding binary unit (or vice versa). E.g., `{ format: kB,
metric: false }` => `KiB`. Instead, this PR adds the `unit` option to
replace the `format` and `metric` options. `unit` can be set to a fixed
file size unit like `kB` or `KiB`, or it can be set to one of the
special options: `binary` or `metric`. These options tells nushell to
format file sizes using an appropriately scaled metric or binary unit
(examples below).
```nushell
# precision = null
# unit = kB
1kB # 1 kB
1KiB # 1.024 kB
# unit = KiB
1kB # 0.9765625 KiB
1KiB # 1 KiB
# unit = metric
1000B # 1 kB
1024B # 1.024 kB
10_000MB # 10 GB
10_240MiB # 10.73741824 GB
# unit = binary
1000B # 1000 B
1024B # 1 KiB
10_000MB # 9.313225746154785 GiB
10_240MiB # 10 GiB
```
- In addition, this PR also adds the `precision` option to the filesize
config. It determines how many digits to show after the decimal point.
If set to null, then everything after the decimal point is shown.
- The default filesize config is `{ unit: metric, precision: 1 }`.
# User-Facing Changes
- Commands that use the config to format file sizes will follow the
changes described above (e.g., `table`, `into string`, `to text`, etc.).
- The file size unit/format passed to `format filesize` is now case
sensitive. An error with the valid units is shown if the case does not
match.
- `$env.config.filesize.format` and `$env.config.filesize.metric` are
deprecated and replaced by `$env.config.filesize.unit`.
- A new `$env.config.filesize.precision` option was added.
# Tests + Formatting
Mostly updated test expected outputs.
# After Submitting
This PR does not change the way NUON serializes file sizes, because that
would require changing the nu parser to be able to losslessly decode the
new, exact string representation introduced in this PR.
Similarly, this PR also does not change the file size parsing in any
way. Although the file size units provided to `format filesize` or the
filesize config are now case-sensitive, the same is not yet true for
file size literals in nushell code.
# Description
Fixes multiple issues related to `ENV_CONVERSION` and
path-conversion-to-list.
* #14681 removed some calls to `convert_env_values()`, but we found that
this caused `nu -n` to no longer convert the path properly.
* `ENV_CONVERSIONS` have apparently never preserved case, meaning a
conversion with a key of `foo` would not update `$env.FOO` but rather
create a new environment variable with a different case.
* There was a partial code-path that attempted to solve this for `PATH`,
but it only worked for `PATH` and `Path`.
* `convert_env_values()`, which handled `ENV_CONVERSIONS` was called in
multiple places in the startup depending on flags.
This PR:
* Refactors the startup to handle the conversion in `main()` rather than
in each potential startup path
* Updates `get_env_var_insensitive()` functions added in #14390 to
return the name of the environment variable with its original case. This
allows code that updates environment variables to preserve the case.
* Makes use of the updated function in `ENV_CONVERSIONS` to preserve the
case of any updated environment variables. The `ENV_CONVERSION` key
itself is still case **insensitive**.
* Makes use of the updated function to preserve the case of the `PATH`
environment variable (normally handled separately, regardless of whether
or not there was an `ENV_CONVERSION` for it).
## Before
`env_convert_values` was run:
* Before the user `env.nu` ran, which included `nu -c <commandstring>`
and `nu <script.nu>`
* Before the REPL loaded, which included `nu -n`
## After
`env_convert_values` always runs once in `main()` before any config file
is processed or the REPL is started
# User-Facing Changes
Bug fixes
# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
Added additional tests to prevent future regression.
# After Submitting
There is additional cleanup that should probably be done in
`convert_env_values()`. This function previously handled
`ENV_CONVERSIONS`, but there is no longer any need for this since
`convert_env_vars()` runs whenever `$env.ENV_CONVERSIONS` changes now.
This means that the only relevant task in the old `convert_env_values()`
is to convert the `PATH` to a list, and ensure that it is a list of
strings. It's still calling the `from_string` conversion on every
variable (just once) even though there are no `ENV_CONVERSIONS` at this
point.
Leaving that to another PR though, while we get the core issue fixed
with this one.
Related:
- #14329
- #13872
- #8214
# Description & User-Facing Changes
This PR allows enables the following uses, which are all no-op.
```nushell
source null
source-env null
use null
overlay use null
```
The motivation for this change is conditional sourcing of files. For
example, with this change `login.nu` may be deprecated and replaced with
the following code in `config.nu`
```nushell
const login_module = if $nu.is-login { "login.nu" } else { null }
source $login_module
```
# Tests + Formatting
I'm hoping for CI to pass 😄
# After Submitting
Add a part about the conditional sourcing pattern to the website.
# Description
A follow-on to #14727:
* Instead of using `is-interactive` as the trigger for incrementing
`SHLVL`, this change puts the increment logic just before `run_repl()`
is called.
* Tests are changed to use `-e`
* Moves the `confirm_stdin_is_terminal()` call immediately **after** the
`prerun_cmd` (which executes `--execute (-e) <commandstring>`. The fact
that it was **before** that call seems to be a bug, since the error
message says *"or provide arguments to invoke a script"* even if
`--execute` was used. This change enables REPL testing using `--execute
(-e)`.
* Added a test to ensure `-c` does *not* increment SHLVL.
# User-Facing Changes
`$env.SHLVL` runs before the REPL is started, rather than when
`is-interactive`
# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
# After Submitting
N/A
Tests for #14707 are causing hangs which are preventing `toolkit test`
from completing on some systems. This appears to be due to the use of
`-i` to force interactive mode, which is required in order to update the
`SHLVL`. Both tests are likely attempting to acquire the terminal at the
same time, and one is hanging as a result.
This is a temporary fix which runs both of these tests sequentially.
It's temporary because we need to find a solution which doesn't use
`-i`, since any other future `-it` test will cause the same situation
again.
# Description
Rework of #14570, fixing #14567.
`exec` will decrement `SHLVL` env value before passing it to target
executable (in interactive mode).
(Same as last pr, but this time there's no wrong change to current
working code)
Two `SHLVL` related tests were also added this time.
- this PR should close#14514
# Description
Makes updates to `$env.ENV_CONVERSIONS` take effect immediately.
# User-Facing Changes
No breaking change, `$env.ENV_CONVERSIONS` can be set and its effect
used in the same file.
# Tests + Formatting
- 🟢 toolkit fmt
- 🟢 toolkit clippy
- 🟢 toolkit test
- 🟢 toolkit test stdlib
# After Submitting
N/A
Just a quick change: the test I made for `--no-newline` was missing
`--no-config-file`, so it could false-negative if you have problems with
your config.
# Description
The `.nu-env` file feature was removed some time ago (probably in the
engine-q upgrade?). The tests, however, still remained as dead-code, so
this is just some basic clean-up.
If this feature was ever implemented again, the tests would need to be
rewritten anyway due to the changes in the way config is handled.
# User-Facing Changes
None
# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
-
# After Submitting
N/A
# Release Notes Excerpt
* Hooks now default to an empty value of the proper type (e.g., `[]` or
`{}`) when not otherwise specified
# Description
```nushell
# Start with no config
nu -n
# Populate with defaults
$env.config = {}
$env.config.hooks
```
* Before: All hooks other than `display_output` were set to `null`.
Attempting to append a hook using `++=` would fail unless it had already
been assigned.
* After:
* `pre_prompt`, `pre_execution`, and `command_not_found` are set to
empty lists. This allows the user to simply append new hooks using
`++=`.
* `env_change` is set to an empty record. This allows the user to add
new hooks using `merge`, although a "helper" command would still be
useful (TODO: stdlib).
Also fixed a typo in an error message.
# User-Facing Changes
There shouldn't be any breaking changes since (before) there were no
guarantees of the hook's value/type. Previously, users would have to
check for `null` and `default` to an empty list before appending. Any
user-strategies for dealing with the problem should continue to work
after this change.
# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
Note that, for reasons I cannot ascertain, this PR appears to have
*fixed* the `command_not_found_error_recognizes_non_executable_file`
test that was previously broken by #12953. That PR essentially rewrote
the test to match the new behavior, but it no longer tested what it was
intended to test.
Now, the test is working again as designed (and as it works in the
REPL).
# After Submitting
This will be covered in the Configuration update for #14249. This PR
will simplify several examples in the doc.