Repository navigation
random-list: fix dice and the error helper on current nushell - #1301
qodelicious wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
The std/random import and the span change work on 0.116.2. What's left is argument checks that let 0 through.
Findings: 0
Open (4)
Notes from my clanker, checked on 84629e8 with nu 0.116.2. I ran every random-list subcommand with valid input, 0, negative counts, an out-of-range --bias, and dice counts of 0 and 1.
| @@ -7,8 +9,7 @@ def throw-error [ | |||
| msg: $"(ansi red_bold)($error)(ansi reset)" | |||
There was a problem hiding this comment.
msg
ansi red_bold and ansi reset are baked into the message string, so try { random-list bool -1 } catch {|e| $e.msg } returns "\e[1;31mvalue_error\e[0m", even with NO_COLOR=1. The error renderer already colors the headline, and msg: $error keeps $e.msg easy to match. This was already there before the PR.
| @@ -1,3 +1,5 @@ | |||
| use std/random | |||
There was a problem hiding this comment.
std/random's dice
With this import, random dice is std's version, which asserts --dice > 0 and --sides > 1. The checks in random-list dice only reject negatives, so random-list dice 1 -r 0, -s 0 and -s 1 pass them and fail inside std, with the label at std/random/mod.nu:16/:17 instead of on the user's flag. Checking $roll_count < 1 and $side_count < 2, with messages that say so, keeps the error on the argument.
nu_scripts/modules/random-list/random-list.nu
Lines 74 to 79 in 84629e8
| text: $msg | ||
| start: $span.start | ||
| end: $span.end | ||
| span: $span |
There was a problem hiding this comment.
start/end label is still used in other scripts
modules/network/remoting/remoting.nu:76-77, sourced/filesystem/cdpath.nu:157-158 and sourced/fun/spark.nu:33 still pass start/end, which fails with "Value is missing required columns" on 0.116.2 when those errors fire. Fine as a follow-up if you'd rather keep this PR to random-list.
There was a problem hiding this comment.
The guards only reject < 0, so 0 gets through, and 1..0 counts down to [1, 0]. random-list bool 0 | length, random-list uuid 0 | length and random-list dice 0 | length all return 2 on 0.116.2. Every subcommand uses the same 1..$list_length loop (lines 29, 46, 60, 81, 95 and 108), and 0..<$list_length gives 0 items for 0 and n items for n. The message "must be greater than 0" also says 0 is invalid while the check accepts it; "must not be negative" matches the check. This was already there before the PR, but the description says every subcommand returns what it should.
nu_scripts/modules/random-list/random-list.nu
Lines 25 to 31 in 84629e8



random-list dicedidn't parse on current nushell becauserandom dicemoved out of the builtins intostd/random. The module now doesuse std/randomat the top.While testing that I also hit the error helper failing with "missing span column", since
error makewantsspanin the label now instead of separatestartandend. It passes the span through directly so the validation errors show up again.Tested on 0.116.1.
nu --ide-checkis clean, everyrandom-listsubcommand returns what it should, and passing a negative count or a bias above 1 shows the right error pointing at the argument.