Repository: nushell/nushell
File: crates/nu-command/src/filesystem/watch.rs (Rust)

Code before:

        let debounce_duration_flag: Option<Spanned<Value>> =
            call.get_flag(engine_state, stack, "debounce")?;

        let debounce_duration: Duration;
        match (debounce_duration_flag, debounce_duration_flag_ms) {
            (None, None) => debounce_duration = DEFAULT_WATCH_DEBOUNCE_DURATION,
            (Some(l), Some(r)) => {
                return Err(ShellError::IncompatibleParameters {
                    left_message: "Here".to_string(),
                    left_span: l.span,
                    right_message: "and here".to_string(),
                    right_span: r.span,
                });
            }
            (None, Some(val)) => {
                debounce_duration = match u64::try_from(val.item) {
                    Ok(val) => Duration::from_millis(val),
                    Err(_) => {
                        return Err(ShellError::TypeMismatch {
                            err_message: "Debounce duration is invalid".to_string(),
                            span: val.span,
                        });
                    }
                }
            }
            (Some(v), None) => match v.item {
                dur @ Value::Duration { val, .. } => {
                    debounce_duration = match u64::try_from(val) {
                        Ok(d) => Duration::from_nanos(d),
                        Err(_) => {
                            return Err(ShellError::TypeMismatch {
                                err_message: "Debounce duration is invalid".to_string(),
                                span: dur.span(),
                            });
                        }
                    };
                }
                // This should be unreachable, as the parser will fail
                // before this is ever called. I will leave it in anyways
                // so we can handle it gracefully once it never arrives
                any => {
                    return Err(ShellError::TypeMismatch {
                        err_message: "Debounce duration must be a duration".to_string(),
                        span: any.span(),
                    });
                }
            },
        }

        let glob_flag: Option<Spanned<String>> = call.get_flag(engine_state, stack, "glob")?;

Review comment (suggestion):
Pinging @132ikl on how we now raise the deprecation warning correctly since https://github.com/nushell/nushell/pull/16147 

The `ShellError::DeprecationWarning` still exists but I guess that is not the way to go anymore.

Code after:
        };

        let closure: Closure = call.req(engine_state, stack, 1)?;

        let verbose = call.has_flag(engine_state, stack, "verbose")?;

        let quiet = call.has_flag(engine_state, stack, "quiet")?;

        let debounce_duration_flag_ms: Option<Spanned<i64>> =
            call.get_flag(engine_state, stack, "debounce-ms")?;

        let debounce_duration_flag: Option<Spanned<Value>> =
            call.get_flag(engine_state, stack, "debounce")?;

        let debounce_duration: Duration = match (debounce_duration_flag, debounce_duration_flag_ms)
        {
            (None, None) => DEFAULT_WATCH_DEBOUNCE_DURATION,
            (Some(l), Some(r)) => {
                return Err(ShellError::IncompatibleParameters {
                    left_message: "Here".to_string(),
                    left_span: l.span,
                    right_message: "and here".to_string(),
                    right_span: r.span,
                });
            }
            (None, Some(val)) => match u64::try_from(val.item) {
                Ok(v) => Duration::from_millis(v),
                Err(_) => {
                    return Err(ShellError::TypeMismatch {
                        err_message: "Debounce duration is invalid".to_string(),
                        span: val.span,
                    });
                }
            },
            (Some(v), None) => {
                let Value::Duration { val, .. } = v.item else {
                    return Err(ShellError::TypeMismatch {
                        err_message: "Debounce duration must be a duration".to_string(),
                        span: v.item.span(),
                    });
                };
                Duration::from_nanos(u64::try_from(val).map_err(|_| ShellError::TypeMismatch {
                    err_message: "Debounce duration is invalid".to_string(),
                    span: v.item.span(),
                })?)
            }
        };

        let glob_flag: Option<Spanned<String>> = call.get_flag(engine_state, stack, "glob")?;
        let glob_pattern = match glob_flag {
            Some(glob) => {