{"record":{"id":"249edac15aa51163","repo":"rust-lang/mdBook","slug":"ignore-root-canonicalize-error-249eda","errorCode":null,"errorMessage":"ignore root canonicalize error","messagePattern":"ignore root canonicalize error","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/watch/poller.rs","lineNumber":113,"sourceCode":"impl Watcher {\n    fn new(book_root: &Path) -> Watcher {\n        // FIXME: ignore should be reloaded when it changes.\n        let ignore = super::find_gitignore(book_root).map(|gitignore_path| {\n            let (ignore, err) = Gitignore::new(&gitignore_path);\n            if let Some(err) = err {\n                warn!(\n                    \"error reading gitignore `{}`: {err}\",\n                    gitignore_path.display()\n                );\n            }\n            // Note: The usage of `canonicalize` may encounter occasional\n            // failures on the Windows platform, presenting a potential risk.\n            // For more details, refer to [Pull Request\n            // #2229](https://github.com/rust-lang/mdBook/pull/2229#discussion_r1408665981).\n            let ignore_path = ignore\n                .path()\n                .canonicalize()\n                .expect(\"ignore root canonicalize error\");\n            (ignore_path, ignore)\n        });\n\n        Watcher {\n            ignore,\n            ..Default::default()\n        }\n    }\n\n    /// Sets the root directories where scanning will start.\n    fn set_roots(&mut self, book: &MDBook) {\n        let mut root_paths = vec![\n            book.source_dir(),\n            book.theme_dir(),\n            book.root.join(\"book.toml\"),\n        ];\n        root_paths.extend(\n            book.config","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/rust-lang/mdBook/blob/dc21064fc21d955a0e1f67e65e336883c3e5260b/src/cmd/watch/poller.rs#L95-L131","documentation":"In poller.rs `new`, the gitignore root is canonicalized with `.expect(\"ignore root canonicalize error\")` — same guard as native.rs. Failure (missing dir, broken symlink, Windows canonicalize quirk per PR #2229) panics while constructing the poller.","triggerScenarios":"Creating the WatchLater/Poller during `mdbook watch` when the directory backing the gitignore (`ignore.path()`) cannot be canonicalized: directory removed between parse and poller construction, invalid symlink, Windows-specific canonicalize failure (UNC/network paths).","commonSituations":"Book root deleted or renamed right as watch starts; race where book dir is temporarily unmounted; Windows network drives.","solutions":["Ensure the book root exists and is a resolvable path before `mdbook watch`.","Run watch from a local (not network/UNC) path on Windows.","Patch to fall back: `canonicalize().unwrap_or_else(|_| ignore.path().to_path_buf())`.","Upgrade mdbook to a release that softens this canonicalize expect."],"exampleFix":"// before\nlet ignore_path = ignore.path().canonicalize().expect(\"ignore root canonicalize error\");\n// after\nlet ignore_path = ignore\n    .path()\n    .canonicalize()\n    .unwrap_or_else(|_| ignore.path().to_path_buf());","handlingStrategy":"fallback","validationCode":"let p = ignore.path();\nif !p.exists() {\n    eprintln!(\"cannot start watcher: ignore root {:?} missing\", p);\n    std::process::exit(1);\n}\nlet _ = p.canonicalize()?; // fail early, not via expect","typeGuard":null,"tryCatchPattern":"let ignore_path = ignore.path().canonicalize().unwrap_or_else(|e| {\n    log::warn!(\"ignore root canonicalize failed: {e}\");\n    ignore.path().to_path_buf()\n});","preventionTips":["Verify book root exists before starting `mdbook watch`.","Watch local directories, not network mounts, on Windows.","Re-create the poller if the book root moves mid-session.","Upgrade mdbook / soften canonicalize expects."],"tags":["filesystem","panic","windows","canonicalize","poller"],"backgroundTag":"path-canonicalize-failed","analyzedSha":"dc21064fc21d955a0e1f67e65e336883c3e5260b","analyzedAt":"2026-09-01T10:15:12.134Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}