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

Code before:
                debounce_duration = 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) => 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")?;
        let glob_pattern = match glob_flag {
            Some(glob) => {
                let absolute_path = path.join(glob.item);
                if verbose {
                    eprintln!("Absolute glob path: {absolute_path:?}");
                }

                match nu_glob::Pattern::new(&absolute_path.to_string_lossy()) {
                    Ok(pattern) => Some(pattern),
                    Err(_) => {
                        return Err(ShellError::TypeMismatch {
                            err_message: "Glob pattern is invalid".to_string(),
                            span: glob.span,
                        });
                    }
                }

Review comment (suggestion):
I think we can just do this here:

```suggestion
            (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.span,
                    });
                }
                val
```

this suggestion won't apply cleanly since I can't do a suggestion over unchanged lines, but the `any` match branch would have to be manually removed as well

Code after:
                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) => {
                let absolute_path = path.join(glob.item);
                if verbose {
                    eprintln!("Absolute glob path: {absolute_path:?}");
                }

                match nu_glob::Pattern::new(&absolute_path.to_string_lossy()) {
                    Ok(pattern) => Some(pattern),
                    Err(_) => {
                        return Err(ShellError::TypeMismatch {
                            err_message: "Glob pattern is invalid".to_string(),
                            span: glob.span,
                        });
                    }
                }
            }
            None => None,
        };

        let recursive_flag: Option<Spanned<bool>> =
            call.get_flag(engine_state, stack, "recursive")?;
        let recursive_mode = match recursive_flag {
            Some(recursive) => {
                if recursive.item {
                    RecursiveMode::Recursive
                } else {
                    RecursiveMode::NonRecursive