Skip to content

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

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

implement FromValue for std::time::Duration and refactor relevant commands to utilize that#16414
sholderbach merged 3 commits intonushell:mainfrom
Bahex:FromValue-for-Duration

Conversation

@Bahex
Copy link
Copy Markdown
Member

@Bahex Bahex commented Aug 11, 2025

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
         ╰────
      

Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

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
16 checks passed
@github-actions github-actions bot added this to the v0.107.0 milestone Aug 12, 2025
@Bahex Bahex added the notes:ready The "Release notes summary" section of this PR is ready to be included in our release notes. label Aug 30, 2025
@WindSoilder WindSoilder added the notes:mention Include the release notes summary in the "Hall of Fame" section label Aug 31, 2025
@Bahex Bahex deleted the FromValue-for-Duration branch March 22, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:mention Include the release notes summary in the "Hall of Fame" section notes:ready The "Release notes summary" section of this PR is ready to be included in our release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants