rust-lang/rust-analyzer · error
Project discovery failed: {error}
Error message
Project discovery failed: {error} What it means
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.
Source
Thrown at crates/rust-analyzer/src/main_loop.rs:1154
match message {
DiscoverProjectMessage::Finished { project, buildfile } => {
self.discover_jobs_active = self.discover_jobs_active.saturating_sub(1);
if self.discover_jobs_active == 0 {
self.report_progress(&title, Progress::End, None, None, None);
}
let mut config = Config::clone(&*self.config);
config.add_discovered_project_from_command(project, buildfile);
self.update_configuration(config);
}
DiscoverProjectMessage::Progress { message } => {
if self.discover_jobs_active > 0 {
self.report_progress(&title, Progress::Report, Some(message), None, None)
}
}
DiscoverProjectMessage::Error { error, source } => {
let message = format!("Project discovery failed: {error}");
self.show_and_log_error(message.clone(), source);
self.discover_jobs_active = self.discover_jobs_active.saturating_sub(1);
if self.discover_jobs_active == 0 {
self.report_progress(&title, Progress::End, Some(message), None, None)
}
}
}
}
/// Drop any discover command processes that have exited, due to
/// finishing or erroring.
fn cleanup_discover_handles(&mut self) {
let mut active_handles = vec![];
for mut discover_handle in self.discover_handles.drain(..) {
if !discover_handle.handle.has_exited() {
active_handles.push(discover_handle);
}View on GitHub (pinned to e8f7e90aa3)
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).
Example fix
// before (settings.json)
"rust-analyzer.discoverProjectConfig": { "command": ["./discover.py"] } // script exits 1
// after
"rust-analyzer.discoverProjectConfig": { "command": ["python3", "/abs/path/discover.py"] },
// and ensure the script prints rust-project JSON and exits 0 Defensive patterns
Strategy: fallback
Validate before calling
# Validate the discovery command before configuring it: ./your-discover-command | jq -e '.crates' > /dev/null && echo OK || echo BAD_DISCOVERY_OUTPUT
Try / catch
client.onNotification(lsp.ShowMessageNotification.type, (p) => {
if (p.message.startsWith('Project discovery failed')) {
// fall back to a static rust-project.json via linkedProjects
}
}); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot rename builtin type
- cargo check failed to start: {err}
- {message}
- We explicitly do not provide canonicalization API, as that i
- bad kind {other}
AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03).
Data as JSON: /api/errors/72c234609373c3e1.
Report an issue: GitHub.