{"record":{"id":"8ac9b35de867a5dc","repo":"rust-lang/rust-analyzer","slug":"unable-to-get-fileid","errorCode":null,"errorMessage":"unable to get FileId","messagePattern":"unable to get FileId","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rust-analyzer/src/main_loop.rs","lineNumber":1091,"sourceCode":"                            Some(message),\n                            Some(Progress::fraction(n_done, n_total)),\n                            None,\n                        )\n                    }\n                }\n            }\n        }\n    }\n\n    fn handle_deferred_task(&mut self, task: DeferredTask) {\n        match task {\n            DeferredTask::CheckIfIndexed(uri) => {\n                let snap = self.snapshot();\n\n                self.task_pool.handle.spawn_with_sender(ThreadIntent::Worker, move |sender| {\n                    let _p = tracing::info_span!(\"GlobalState::check_if_indexed\").entered();\n                    tracing::debug!(?uri, \"handling uri\");\n                    let Some(id) = from_proto::file_id(&snap, &uri).expect(\"unable to get FileId\")\n                    else {\n                        return;\n                    };\n                    if let Ok(crates) = &snap.analysis.crates_for(id) {\n                        if crates.is_empty() {\n                            if snap.config.discover_workspace_config().is_some() {\n                                let path =\n                                    from_proto::abs_path(&uri).expect(\"Unable to get AbsPath\");\n                                let arg = DiscoverProjectParam::Path(path);\n                                sender.send(Task::DiscoverLinkedProjects(arg)).unwrap();\n                            }\n                        } else {\n                            tracing::debug!(?uri, \"is indexed\");\n                        }\n                    }\n                });\n            }\n            DeferredTask::CheckProcMacroSources(modified_rust_files) => {","sourceCodeStart":1073,"sourceCodeEnd":1109,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/rust-analyzer/src/main_loop.rs#L1073-L1109","documentation":"CheckIfIndexed deferred task converts a file URI into an internal FileId and only then checks index status. The code already handles None gracefully via if-let, so the expect fires only when from_proto::file_id returns Err — i.e. the URI cannot be converted (unsupported scheme such as untitled:/, or URL parsing failure). Since the error case is otherwise handled, this expect is an over-strict assertion on an unreachable-in-practice branch.","triggerScenarios":"A textDocument URI with a non-file scheme (untitled:, vscode-notebook-cell:, remote authority prefixes) or a malformed URI reaching the CheckIfIndexed task after didOpen/didChange, causing from_proto::file_id to return Err instead of Ok(None).","commonSituations":"Editing untitled scratch files, remote/SSH or web (VS Code web) development where URIs carry non-standard schemes, extensions that synthesize virtual document URIs, and notebooks embedding Rust code.","solutions":["Avoid running rust-analyzer analysis over virtual/untitled URIs, or save the file to disk first.","Upgrade rust-analyzer — this branch should map Err to the existing `return` path instead of panicking.","Identify which extension/client produced the URI from logs (the `?uri` debug field) and disable the offending virtual-document provider for .rs files.","As a workaround, disable workspace linking/deferred indexing on that URI by closing the virtual editor."],"exampleFix":"// before\nlet Some(id) = from_proto::file_id(&snap, &uri).expect(\"unable to get FileId\") else { return; };\n// after: treat conversion error like the not-found case\nlet Ok(id) = from_proto::file_id(&snap, &uri) else { return; };","handlingStrategy":"fallback","validationCode":"// server-side guard: skip non-file URIs before the deferred task\nif uri.scheme().as_str() != \"file\" { return; }","typeGuard":"fn is_file_uri(uri: &lsp_types::Url) -> bool {\n    uri.scheme() == \"file\"\n}","tryCatchPattern":"// if you cannot patch the server, avoid triggering it client-side\nif (doc.uri.scheme !== 'file') { return; } // don't expect indexing for untitled/virtual docs","preventionTips":["Save untitled Rust files to disk before expecting analysis features.","Exclude virtual document providers (notebooks, scratch pads) from rust-analyzer activation.","Keep rust-analyzer updated; this expect is a known over-strict assertion.","Check the logged `?uri` when diagnosing which producer sent the bad URI."],"tags":["lsp","uri","panic","indexing","virtual-documents"],"backgroundTag":"unconvertible-document-uri","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"}