{"record":{"id":"6d2a9e1b4678930f","repo":"rust-lang/mdBook","slug":"unsupported-watcher-s","errorCode":null,"errorMessage":"unsupported watcher {s}","messagePattern":"unsupported watcher (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/watch.rs","lineNumber":31,"sourceCode":"    Command::new(\"watch\")\n        .about(\"Watches a book's files and rebuilds it on changes\")\n        .arg_dest_dir()\n        .arg_root_dir()\n        .arg_open()\n        .arg_watcher()\n}\n\npub enum WatcherKind {\n    Poll,\n    Native,\n}\n\nimpl WatcherKind {\n    pub fn from_str(s: &str) -> WatcherKind {\n        match s {\n            \"poll\" => WatcherKind::Poll,\n            \"native\" => WatcherKind::Native,\n            _ => panic!(\"unsupported watcher {s}\"),\n        }\n    }\n}\n\n// Watch command implementation\npub fn execute(args: &ArgMatches) -> Result<()> {\n    let book_dir = get_book_dir(args);\n    let mut book = MDBook::load(&book_dir)?;\n\n    let update_config = |book: &mut MDBook| {\n        set_dest_dir(args, book);\n    };\n    update_config(&mut book);\n\n    if args.get_flag(\"open\") {\n        book.build()?;\n        let path = book.build_dir_for(\"html\").join(\"index.html\");\n        if !path.exists() {","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/rust-lang/mdBook/blob/dc21064fc21d955a0e1f67e65e336883c3e5260b/src/cmd/watch.rs#L13-L49","documentation":"The WatcherKind::from_str parser in mdbook's watch command accepts exactly \"poll\" or \"native\" for the watcher implementation; any other value panics with `unsupported watcher {s}`. There is no graceful CLI validation, so an invalid --watcher argument crashes with this panic instead of an argument error.","triggerScenarios":"Running mdbook watch/serve with a watcher value other than \"poll\" or \"native\" (e.g. mdbook serve --watcher notify, --watcher auto, or a typo like --watcher natve), or calling WatcherKind::from_str programmatically with arbitrary strings.","commonSituations":"Typo in a script or alias, copying a flag value from another tool, stale documentation referencing a removed watcher name, or an old wrapper script predating the current flag values.","solutions":["Use exactly --watcher native or --watcher poll on the command line.","Fix typos in scripts/aliases that pass the watcher value.","If the platform has native-watcher issues, use --watcher poll which works everywhere.","If writing integrations, validate the string against {poll,native} before calling from_str."],"exampleFix":"// before\nmdbook serve --watcher notify\n\n// after\nmdbook serve --watcher native","handlingStrategy":"validation","validationCode":"const WATCHERS: [&str; 2] = [\"poll\", \"native\"];\nfn valid_watcher(s: &str) -> bool { WATCHERS.contains(&s) }\nassert!(valid_watcher(args.watcher), \"--watcher must be 'poll' or 'native'\");","typeGuard":"fn is_watcher_kind(s: &str) -> Option<&'static str> {\n    match s {\n        \"poll\" | \"native\" => Some(s),\n        _ => None,\n    }\n}","tryCatchPattern":"// invoke via CLI wrapper that parses the flag first\nif let Err(e) = parse_watcher_flag(cli_args) {\n    eprintln!(\"invalid --watcher value: {e}; use 'poll' or 'native'\");\n    std::process::exit(2);\n}","preventionTips":["Only pass literal \"poll\" or \"native\" to --watcher.","Validate flags in wrapper scripts before invoking mdbook.","Prefer \"poll\" in environments where native watcher support is uncertain."],"tags":["cli","invalid-argument","watcher","panic"],"backgroundTag":"invalid-enum-string-value","analyzedSha":"dc21064fc21d955a0e1f67e65e336883c3e5260b","analyzedAt":"2026-09-01T10:15:12.134Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}