{"record":{"id":"72c234609373c3e1","repo":"rust-lang/rust-analyzer","slug":"project-discovery-failed-error","errorCode":null,"errorMessage":"Project discovery failed: {error}","messagePattern":"Project discovery failed: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rust-analyzer/src/main_loop.rs","lineNumber":1154,"sourceCode":"        match message {\n            DiscoverProjectMessage::Finished { project, buildfile } => {\n                self.discover_jobs_active = self.discover_jobs_active.saturating_sub(1);\n                if self.discover_jobs_active == 0 {\n                    self.report_progress(&title, Progress::End, None, None, None);\n                }\n\n                let mut config = Config::clone(&*self.config);\n                config.add_discovered_project_from_command(project, buildfile);\n                self.update_configuration(config);\n            }\n            DiscoverProjectMessage::Progress { message } => {\n                if self.discover_jobs_active > 0 {\n                    self.report_progress(&title, Progress::Report, Some(message), None, None)\n                }\n            }\n            DiscoverProjectMessage::Error { error, source } => {\n                let message = format!(\"Project discovery failed: {error}\");\n                self.show_and_log_error(message.clone(), source);\n\n                self.discover_jobs_active = self.discover_jobs_active.saturating_sub(1);\n                if self.discover_jobs_active == 0 {\n                    self.report_progress(&title, Progress::End, Some(message), None, None)\n                }\n            }\n        }\n    }\n\n    /// Drop any discover command processes that have exited, due to\n    /// finishing or erroring.\n    fn cleanup_discover_handles(&mut self) {\n        let mut active_handles = vec![];\n\n        for mut discover_handle in self.discover_handles.drain(..) {\n            if !discover_handle.handle.has_exited() {\n                active_handles.push(discover_handle);\n            }","sourceCodeStart":1136,"sourceCodeEnd":1172,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/rust-analyzer/src/main_loop.rs#L1136-L1172","documentation":"When the project discovery subsystem (used for non-Cargo workspaces, e.g. the DiscoverWorkspaceConfig command) reports an error, handle_discover_msg formats 'Project discovery failed: {error}', shows it via show_and_log_error (with the optional source detail), and ends the corresponding progress. It means rust-analyzer could not construct a workspace model for the project.","triggerScenarios":"DiscoverProjectMessage::Error arriving from a discovery job — the user-configured discovery command exited non-zero, emitted invalid JSON, or failed to describe the workspace; discover_jobs_active is decremented and progress ends with the error message.","commonSituations":"Misconfigured `rust-analyzer.discoverProjectConfig`/custom discovery command (wrong path, non-JSON output, script errors); monorepo/non-Cargo layouts where the discovery script assumptions break; missing tooling in the environment the script runs in.","solutions":["Run your discovery command manually and confirm it emits valid `DiscoverProjectData` JSON on stdout.","Fix the script/binary path in the DiscoverProjectConfig (check stdout/stderr routing and exit code).","Inspect the `source` detail appended to the notification and the rust-analyzer log for the underlying error.","Fall back to linkedProjects with a hand-written rust-project.json if custom discovery is unreliable.","Update the discovery script after toolchain/layout changes (new subcrates, moved Cargo.toml files)."],"exampleFix":"// before (settings.json)\n\"rust-analyzer.discoverProjectConfig\": { \"command\": [\"./discover.py\"] } // script exits 1\n// after\n\"rust-analyzer.discoverProjectConfig\": { \"command\": [\"python3\", \"/abs/path/discover.py\"] },\n// and ensure the script prints rust-project JSON and exits 0","handlingStrategy":"fallback","validationCode":"# Validate the discovery command before configuring it:\n./your-discover-command | jq -e '.crates' > /dev/null && echo OK || echo BAD_DISCOVERY_OUTPUT","typeGuard":null,"tryCatchPattern":"client.onNotification(lsp.ShowMessageNotification.type, (p) => {\n  if (p.message.startsWith('Project discovery failed')) {\n    // fall back to a static rust-project.json via linkedProjects\n  }\n});","preventionTips":["Test the discovery command manually: valid JSON on stdout, exit code 0, diagnostics on stderr.","Provide a linkedProjects rust-project.json fallback for non-Cargo workspaces.","Re-run/update discovery scripts after workspace layout or toolchain changes.","Check the `source` detail in the notification/log for the script-level error."],"tags":["rust","lsp","project-discovery","configuration"],"backgroundTag":"project-discovery-failed","analyzedSha":"e8f7e90aa3e7b26aa9a000200f606c1078da99ec","analyzedAt":"2026-09-03T21:08:06.959Z","contentChangedAt":"2026-09-03T21:08:06.959Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}