{"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":975,"sourceCode":"        self.recursive\n    }\n\n    #[must_use]\n    fn add(\n        &self,\n        path: Arc<std::path::Path>,\n        case_insensitive: bool,\n        cb: impl Fn(&notify::Event) + Send + Sync + 'static,\n    ) -> anyhow::Result<Option<WatcherRegistrationId>> {\n        let path = SanitizedPath::from_arc(path);\n        let key = WatchKey::for_registration(&path, case_insensitive);\n        let mut state = self.state.lock();\n        let path_already_covered = state\n            .paths\n            .covered_by_recursive_ancestor(&path, self.recursive);\n        let path_already_registered = state.paths.contains(&key);\n\n        if !path_already_covered && !path_already_registered {\n            if self.kind == OsWatcherKind::Native && state.is_native_watch_limit_cooldown_active() {\n                self.diagnostics.record(|| {\n                    WatchDiagnosticEvent::new(\n                        self.kind,\n                        \"watch_skipped\",\n                        &[path.as_path().to_owned()],\n                        \"Native watch limit cooldown is active; registration will be retried\"\n                            .into(),\n                        false,\n                    )\n                });\n                return Ok(None);\n            }\n\n            drop(state);\n            match self.watch(path.as_path()) {\n                Ok(()) => {}\n                Err(error)","sourceCodeStart":957,"sourceCodeEnd":993,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/fs/src/fs_watcher.rs#L957-L993","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":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}