nushell / nushell/nushell

integer underflow on insert into an empty list

Open
#18,426 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:needs-triage
Dominant language
Rust
Stars
40.5k
Forks
2.3k
Avg merge
1d 19h
Merged PRs (30d)
85

Description

Bug report form
  • I have done a basic search of the issue tracker to find any existing issues that are similar.
  • I have checked that my version is at least the latest stable release available via my installation method.
Describe the bug

Firstly, upon running something like [] | insert 0.0 1, instead of getting the expected nested lists containing a 1 ([ [ 1 ] ]), similarly to how it works on records - {} | insert a.0 1 returns {a: [1]}.

Secondly, on an empty list, the error message itself contains an underflowed number.

This can have an easy fix for just the underflow in the error message - using saturating_sub instead of just the minus operator during the construction of the error message (or better, explicitly checking for empty lists with a more descriptive error message) OR a harder fix, that is to fix the inconsistency between the creation of a new nested list/record using the insert command on a list input vs a report input.

I am willing to make the change, as I have stumbled upon this while working on another PR related to the insert command.

Please also note that this issue is also present for the upsert command as well

How to reproduce

[] | insert 0.0 1 or [] | insert 0.a 1

returns this error:

Error: nu::shell::access_beyond_end

  × Row number too large (max: 18446744073709551615).
   ╭─[repl_entry #23:1:13]
 1 │ [] | insert 0.0 1
   ·             ┬
   ·             ╰── index too large (max: 18446744073709551615)
   ╰────

Expected behavior

A list containing a list with one element - [ [ 1 ] ] or a list containing a record with the specified mapping - [ { a: 1} ].

If neither of those behaviours, then at least a properly constructed error message

Configuration

not relevant

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with [] | insert 0.0 1 and [] | insert 0.a 1, then inspect the insert and upsert command handling for empty-list paths. Done means either nested list/record creation matches the stated expected behavior or the error message is constructed without the underflowed maximum.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.