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

Code before:
        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) => 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(v) => {
                        report_shell_error(
                            &engine_state,
                            &ShellError::DeprecationWarning {
                                deprecation_type: "Something",
                                suggestion: "Use the --debounce flag instead".into(),
                                span: val.span,
                                help: Some("--debounce uses a duration instead of an int"),
                            },
                        );
                        Duration::from_millis(v)
                    }
                    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(),
                            });
                        }

Review comment (suggestion):
This I was not sure about. If someone can tell me what its supposed to say, I can adjust it. We should then document this as well

Code after:
            Err(err) => {
                return Err(ShellError::Io(IoError::new(
                    err,
                    path_arg.span,
                    PathBuf::from(path_no_whitespace),
                )));
            }
        };

        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(),