{"record":{"id":"b182bdc5b38be7a4","repo":"zed-industries/zed","slug":"native-watcher-initialized","errorCode":null,"errorMessage":"native watcher initialized","messagePattern":"native watcher initialized","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fs/src/fs_watcher.rs","lineNumber":1000,"sourceCode":"    }\n\n    pub fn remove(&self, id: WatcherRegistrationId) {\n        let mut state = self.state.lock();\n        let Some((path, mode)) = state.remove_registration(id) else {\n            return;\n        };\n        drop(state);\n        self.unwatch(path.as_path(), mode).log_err();\n    }\n\n    fn watch(&self, path: &Path, mode: WatcherMode) -> anyhow::Result<()> {\n        match mode {\n            WatcherMode::Native => {\n                self.ensure_native_watcher()?;\n                self.native_watcher\n                    .lock()\n                    .as_mut()\n                    .expect(\"native watcher initialized\")\n                    .watch(\n                        path,\n                        if cfg!(any(target_os = \"windows\", target_os = \"macos\")) {\n                            notify::RecursiveMode::Recursive\n                        } else {\n                            notify::RecursiveMode::NonRecursive\n                        },\n                    )?;\n            }\n            WatcherMode::Poll => {\n                self.ensure_poll_watcher()?;\n                self.poll_watcher\n                    .lock()\n                    .as_mut()\n                    .expect(\"poll watcher initialized\")\n                    .watch(path, notify::RecursiveMode::Recursive)?;\n            }\n        }","sourceCodeStart":982,"sourceCodeEnd":1018,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/fs/src/fs_watcher.rs#L982-L1018","documentation":"A post-condition guard in the native watch path: ensure_native_watcher() was just called successfully, so the native_watcher field behind the mutex is expected to be Some. The expect fires only if that invariant is broken — ensure_native_watcher succeeded without installing the watcher (a logic contradiction) or another thread tore the watcher down between the two calls. It is an internal consistency check, not an input-driven error.","triggerScenarios":"Thrown at crates/fs/src/fs_watcher.rs:1000 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Have ensure_native_watcher return the &mut watcher it guaranteed, removing the second lock+expect","Treat None as a retryable state: re-run ensure_native_watcher and try again instead of panicking","Hold the same lock across ensure + use so teardown cannot interleave"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}