Skip to content

fix(random): avoid panics when sampling float ranges - #19476

Open
subotac wants to merge 1 commit into
nushell:mainfrom
subotac:fix/random-float-invalid-ranges
Open

subotac wants to merge 1 commit into
nushell:mainfrom
subotac:fix/random-float-invalid-ranges

Conversation

@subotac

@subotac subotac commented Nov 8, 2026

Copy link
Copy Markdown

Description

random float 1..<1 and random float (-1e308)..1e308 currently panic in rand. Use fallible sampling-range constructors and return the existing InvalidRange error when a range cannot be sampled. Preserve descending-range validation and valid inclusive, exclusive and unbounded ranges

Adds regressions for empty ranges, overflowing range widths and negative values.

User-facing changes (Release notes)

random float reports an error for empty or unrepresentable sampling ranges instead of panicking

Additional notes

The actual random test sources pass through a local builtin Rust harness (21 tests). The prescribed custom harness discovers zero tests on this Windows GNU setup, so that invocation is not counted as validation. cargo nuclippy, workspace formatting and typos pass. Full workspace tests and hosted CI have not been run1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant