Skip to content

implement FromValue for std::time::Duration and refactor relevant commands to utilize that - #16414

Merged
sholderbach merged 3 commits into
nushell:mainfrom
Bahex:FromValue-for-Duration
Aug 12, 2025
Merged

sholderbach merged 3 commits into
nushell:mainfrom
Bahex:FromValue-for-Duration

Conversation

@Bahex

@Bahex Bahex commented Aug 11, 2025 •

Copy link
Copy Markdown
Member

Description

  • Implemented FromValue for std::time::Duration.
    • It only converts positive Value::Duration values, negative ones raise ShellError::NeedsPositiveValue.
  • Refactor job recv and watch commands to use this implementation rather than handling it ad-hoc.
    • Simplified watch's debounce & debounce-ms and factored it to a function. Should make removing debounce-ms after its deprecation period ends.
    • job recv previously used a numeric cast (i64 as u64) which would result in extremely long duration values rather than raising an error when negative duration arguments were given.

User-Facing Changes

Release notes summary

N/A


Changes in error messages:

  • Providing the wrong type (bypassing parse time type checking):
    • Before
      Error: nu::shell::type_mismatch
      
        × Type mismatch.
         ╭─[entry #40:1:9]
       1 │ watch . --debounce (1 | $in) {|| }
         ·         ──────────┬─────────
         ·                   ╰── Debounce duration must be a duration
         ╰────
      
    • After
      Error: nu::shell::cant_convert
      
        × Can't convert to duration.
         ╭─[entry #2:1:9]
       1 │ watch . --debounce (1 | $in) {|| }
         ·         ──────────┬─────────
         ·                   ╰── can't convert int to duration
         ╰────
      
  • Providing a negative duration value:
    • Before
      Error: nu::shell::type_mismatch
      
        × Type mismatch.
         ╭─[entry #41:1:9]
       1 │ watch . --debounce -100ms {|| }
         ·         ────────┬────────
         ·                 ╰── Debounce duration is invalid
         ╰────
      
    • After
      Error: nu::shell::needs_positive_value
      
        × Negative value passed when positive one is required
         ╭─[entry #4:1:9]
       1 │ watch . --debounce -100ms {|| }
         ·         ────────┬────────
         ·                 ╰── use a positive value
         ╰────
      

@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.

Nice!

We should probably at some point have our own Duration wrapper that is FromValue friendly and supports the negative durations as well.

@sholderbach
sholderbach merged commit 79a6c78 into nushell:main Aug 12, 2025
@github-actions github-actions Bot added this to the v0.107.0 milestone Aug 12, 2025
@Bahex Bahex added the notes:ready Indicates Ready for Release notes label Aug 30, 2025
@WindSoilder WindSoilder added the notes:mention Noted in "Hall of Fame" section label Aug 31, 2025
@Bahex
Bahex deleted the FromValue-for-Duration branch March 22, 2026 13:03
@Bahex Bahex mentioned this pull request May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:mention Noted in "Hall of Fame" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants