Skip to content

fix: assigment errors point to the assigment - #18531

Merged
Bahex merged 4 commits into
nushell:mainfrom
Bahex:assignment-error-fix
Jul 6, 2026
Merged

Bahex merged 4 commits into
nushell:mainfrom
Bahex:assignment-error-fix

Conversation

@Bahex

@Bahex Bahex commented Jul 5, 2026 •

Copy link
Copy Markdown
Member

Description

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
Code
mut execution_time = -1
$execution_time = $env.CMD_DURATION_MS
Before
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"
   ╰────
After
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
   ╰────
example 2
Code
# 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
Before
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 │ }
   ╰────
After
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
    ╰────

Additional notes

@Bahex Bahex added A:error-unhelpful The error message you observe is not helpful to identify the problem A:type-system Problems or features related to nushell's type system notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes category:experimental-option This is a tracking issue for an experimental option labels Jul 5, 2026
@Bahex Bahex mentioned this pull request Jul 6, 2026
2 tasks done
@Bahex
Bahex merged commit 8560eef into nushell:main Jul 6, 2026
18 checks passed
@github-actions github-actions Bot added this to the v0.115.0 milestone Jul 6, 2026
@Bahex Bahex linked an issue Jul 10, 2026 that may be closed by this pull request
@cptpiepmatz cptpiepmatz modified the milestones: v0.115.0, v0.114.1 Jul 11, 2026
@Bahex
Bahex deleted the assignment-error-fix branch July 28, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:error-unhelpful The error message you observe is not helpful to identify the problem A:type-system Problems or features related to nushell's type system category:experimental-option This is a tracking issue for an experimental option notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhelpful "cant_convert" error pointing to environment variable block

2 participants