rust-lang/rust-analyzer · error

Unable to get AbsPath

Error message

Unable to get AbsPath

What it means

In the same CheckIfIndexed task, when a file has no crates and workspace discovery is configured, the URI is converted to an AbsPath to request linked-project discovery. from_proto::abs_path only succeeds for file:// URIs; the expect panics for any other scheme. The surrounding logic assumes discovery only runs on real filesystem paths, so a non-file URI here is an unhandled input.

Source

Thrown at crates/rust-analyzer/src/main_loop.rs:1099

    }

    fn handle_deferred_task(&mut self, task: DeferredTask) {
        match task {
            DeferredTask::CheckIfIndexed(uri) => {
                let snap = self.snapshot();

                self.task_pool.handle.spawn_with_sender(ThreadIntent::Worker, move |sender| {
                    let _p = tracing::info_span!("GlobalState::check_if_indexed").entered();
                    tracing::debug!(?uri, "handling uri");
                    let Some(id) = from_proto::file_id(&snap, &uri).expect("unable to get FileId")
                    else {
                        return;
                    };
                    if let Ok(crates) = &snap.analysis.crates_for(id) {
                        if crates.is_empty() {
                            if snap.config.discover_workspace_config().is_some() {
                                let path =
                                    from_proto::abs_path(&uri).expect("Unable to get AbsPath");
                                let arg = DiscoverProjectParam::Path(path);
                                sender.send(Task::DiscoverLinkedProjects(arg)).unwrap();
                            }
                        } else {
                            tracing::debug!(?uri, "is indexed");
                        }
                    }
                });
            }
            DeferredTask::CheckProcMacroSources(modified_rust_files) => {
                let analysis = AssertUnwindSafe(self.snapshot().analysis);
                self.task_pool.handle.spawn_with_sender(stdx::thread::ThreadIntent::Worker, {
                    move |sender| {
                        if modified_rust_files.into_iter().any(|file_id| {
                            // FIXME: Check whether these files could be build script related
                            match analysis.crates_for(file_id) {
                                Ok(crates) => crates.iter().any(|&krate| {
                                    analysis.is_proc_macro_crate(krate).is_ok_and(|it| it)

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Restrict discovery config to real filesystem directories and do not open virtual/untitled .rs editors when it is enabled.
  2. Upgrade rust-analyzer: guard this conversion with a graceful return instead of expect.
  3. Check rust.analyzer.workspace.discoverConfig in settings and remove entries matching virtual/remote roots.
  4. Reproduce with the logged `?uri` to find which client feature sends the non-file URI and disable it.

Example fix

// before
let path = from_proto::abs_path(&uri).expect("Unable to get AbsPath");
// after: only attempt discovery for real paths
let Some(path) = from_proto::abs_path(&uri) else { return; };
Defensive patterns

Strategy: validation

Validate before calling

// server-side guard: only run discovery for file:// URIs
if uri.scheme() != "file" { return; }
let path = from_proto::abs_path(&uri).expect("Unable to get AbsPath");

Type guard

fn to_abs_path(uri: &lsp_types::Url) -> Option<AbsPathBuf> {
    from_proto::abs_path(uri).ok()
}

Prevention

When it happens

Trigger: Workspace discovery (rust.analyzer.linkedProjects / discoverWorkspaceConfig) active while a didOpen arrives for a non-file URI — untitled editors, virtual documents, remote scheme URIs — whose file has zero crates, triggering the DiscoverLinkedProjects path.

Common situations: Users with linkedProjects/discovery config enabled opening scratch or notebook Rust files, remote development setups where URIs include authority components, misconfigured discovery pointing at virtual workspaces.

Related errors


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