let binding an existing variable to an invalid object drops the previous binding
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 40.5k
- Forks
- 2.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 85
Description
Describe the bug
When an invalid value is let bound to an existing variable an error occurs as expected, but the previous variable binding is dropped.
Note that declaring a mutable binding let mut foo = "good value" and re-assigning that value directly with $foo = bad_value does keep the previous binding after triggering an error
How to reproduce
~> let foo = "valid string" 02/07/2024 11:04:50 PM
~> $foo 02/07/2024 11:04:57 PM
valid string
~> let foo = invalid_string 02/07/2024 11:05:05 PM
Error: nu::shell::external_command
× External command failed
╭─[entry #6:1:1]
1 │ let foo = invalid_string
· ───────┬──────
· ╰── executable was not found
╰────
help: No such file or directory (os error 2)
~> $foo 02/07/2024 11:05:09 PM
Error: nu::shell::variable_not_found
× Variable not found
╭─[entry #7:1:1]
1 │ $foo
· ──┬─
· ╰── variable not found
╰────
Expected behavior
The variable foo is still accessible as $foo with a value of "valid string"
Screenshots
No response
Configuration
| key | value |
|---|---|
| version | 0.89.1 |
| branch | main |
| commit_hash | 4458aae3d41517d74ce1507ad3e8cd94021feb16 |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.73.0 (cc66ad468 2023-10-03) |
| rust_channel | 1.73.0-x86_64-unknown-linux-gnu |
| cargo_version | cargo 1.73.0 (9c4383fb5 2023-08-26) |
| build_time | 2024-01-20 22:17:23 -05:00 |
| build_rust_channel | release |
| allocator | mimalloc |
| features | dataframe, default, sqlite, trash, which, zip |
| installed_plugins | port list |
Additional context
https://discord.com/channels/601130461678272522/614593951969574961/1205000221571031050
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue in Nushell with the shown let-binding commands, then trace the let binding evaluation and error path to find where the existing binding is removed. Add a regression test that confirms an invalid replacement preserves the previous value, and verify the original reproduction no longer loses $foo.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100