mirror of
https://github.com/nushell/nushell.git
synced 2026-11-24 10:27:07 +08:00
## 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