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
- Restrict discovery config to real filesystem directories and do not open virtual/untitled .rs editors when it is enabled.
- Upgrade rust-analyzer: guard this conversion with a graceful return instead of expect.
- Check rust.analyzer.workspace.discoverConfig in settings and remove entries matching virtual/remote roots.
- 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
- Configure workspace discovery only for real filesystem directories.
- Avoid opening untitled/notebook Rust editors while discovery config is active.
- Audit linkedProjects/discoverConfig entries for remote or virtual roots.
- Update rust-analyzer so the conversion failure returns instead of panicking.
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
- unable to get FileId
- No title could be found; this is a bug
- received response for unknown request
- we never provide completions for excluded files
- we never provide code actions for excluded files
AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03).
Data as JSON: /api/errors/9101182f67982fdd.
Report an issue: GitHub.