Skip to content

Inaccurate error message when using negative index in cell path - #18282

Merged
fdncred merged 3 commits into
nushell:mainfrom
guluo2016:message_issue
Jun 1, 2026
Merged

fdncred merged 3 commits into
nushell:mainfrom
guluo2016:message_issue

Conversation

@guluo2016

@guluo2016 guluo2016 commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR should close #18281

After applying this patch.

/content/nushell/target/release> [["A", "B"], ["1", "2"]] | get  0.-1
Error: nu::parser::error

  × Invalid literal
   ╭─[repl_entry #1:1:35]
 1 │ [["A", "B"], ["1", "2"]] | get  0.-1
   ·                                   ─┬
   ·                                    ╰── negative index is not supported in cell path
   ╰────
/content/nushell/target/release> [1, 2, 3] | reject (-1)
Error: nu::shell::cant_convert

  × Can't convert to cell path.
   ╭─[repl_entry #5:1:20]
 1 │ [1, 2, 3] | reject (-1)
   ·                    ──┬─
   ·                      ╰── can't convert negative number to cell path
   ╰────                                                                                                                                     

User-facing changes (Release notes)

Improved errors for negative indices in cell paths

Improved error messages when negative indices are used in cell paths.

Previously, negative indices could produce misleading "Row number too large" errors (e.g., [["foo", "bar"], ["foo", "baz"]] | get 0.-1) or generic "NeedsPositiveValue" errors (e.g., ["foo", "bar", "baz"] | get (-1)).

Now Nushell reports clear messages such as "negative index is not supported in cell path" or "can't convert negative number to cell path".

Additional notes

@github-actions github-actions Bot added the A:parser Issues related to parsing label May 25, 2026

@sholderbach sholderbach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that!

Lokks good to me.

If you are looking for perfect standardization you could also verify the other locations where a command converts ints to cell paths if they use the same message. Came across the following less specific NeedsPositiveValue on a quick grep:

if val.is_negative() {
Err(ShellError::NeedsPositiveValue { span })
} else {
Ok(CellPath {
members: vec![PathMember::Int {
val: val as usize,
span,
optional: false,
}],
})
}

@guluo2016

Copy link
Copy Markdown
Contributor Author

Thanks for catching that!

Lokks good to me.

If you are looking for perfect standardization you could also verify the other locations where a command converts ints to cell paths if they use the same message. Came across the following less specific NeedsPositiveValue on a quick grep:

Thanks for the review.
The feedback you provided is helpful and important, I'll update it soon. Thanks!

@fdncred
fdncred merged commit 53b805c into nushell:main Jun 1, 2026
17 checks passed
@fdncred

fdncred commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@github-actions github-actions Bot added this to the v0.114.0 milestone Jun 1, 2026
@fdncred fdncred added the notes:fixes Noted in "Bug fixes" section label Jun 1, 2026
@fdncred

fdncred commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Can you update the User Facing changes section please?

@fdncred fdncred added the notes:ready Indicates Ready for Release notes label Jun 1, 2026
@guluo2016

Copy link
Copy Markdown
Contributor Author

Can you update the User Facing changes section please?

Done.
Thanks for reviewing and merging. @fdncred @sholderbach

@guluo2016
guluo2016 deleted the message_issue branch June 8, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:parser Issues related to parsing 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.

Inaccurate error message when using negative index in cell path

3 participants