rust-lang/rust-analyzer · error

Unable to make path absolute

Error message

Unable to make path absolute

What it means

An `expect` panic guard in `DiscoverProjectMessage::new`: when converting the deserialized `DiscoverProjectData::Finished` into a `DiscoverProjectMessage`, the `buildfile` path reported by the discover command is converted to an absolute path and `try_into`/absolutization is `expect`ed to succeed. It fires when the external discover tool reports a build file path that is not absolute (or not normalized), meaning the tool's output violates the contract.

Source

Thrown at crates/rust-analyzer/src/discover.rs:106

#[serde(rename_all = "snake_case")]
enum DiscoverProjectData {
    Finished { buildfile: Utf8PathBuf, project: ProjectJsonData },
    Error { error: String, source: Option<String> },
    Progress { message: String },
}

#[derive(Debug, PartialEq, Clone)]
pub(crate) enum DiscoverProjectMessage {
    Finished { project: ProjectJsonData, buildfile: AbsPathBuf },
    Error { error: String, source: Option<String> },
    Progress { message: String },
}

impl DiscoverProjectMessage {
    fn new(data: DiscoverProjectData) -> Self {
        match data {
            DiscoverProjectData::Finished { project, buildfile, .. } => {
                let buildfile = buildfile.try_into().expect("Unable to make path absolute");
                DiscoverProjectMessage::Finished { project, buildfile }
            }
            DiscoverProjectData::Error { error, source } => {
                DiscoverProjectMessage::Error { error, source }
            }
            DiscoverProjectData::Progress { message } => {
                DiscoverProjectMessage::Progress { message }
            }
        }
    }
}

struct DiscoverProjectParser;

impl JsonLinesParser<DiscoverProjectMessage> for DiscoverProjectParser {
    fn from_line(&self, line: &str, _error: &mut String) -> Option<DiscoverProjectMessage> {
        match serde_json::from_str::<DiscoverProjectData>(line) {
            Ok(data) => {

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Fix the discover command to always emit absolute build-file paths
  2. Make absolutization robust: join relative paths against the workspace root before converting to `AbsPathBuf` instead of expecting success
  3. Replace the `expect` with an error variant (`stdx::never!` plus fallback) so a malformed tool response cannot panic the server
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/rust-analyzer/src/discover.rs:106 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03). Data as JSON: /api/errors/9203ac100365bf00. Report an issue: GitHub.