{"record":{"id":"ff5b484654c5d019","repo":"astral-sh/ruff","slug":"internalerror-ff5b48","errorCode":"InternalError","errorMessage":"Unable to take snapshot for document with URI {uri}","messagePattern":"Unable to take snapshot for document with URI (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_server/src/server/api/notifications/did_open.rs","lineNumber":37,"sourceCode":"            text_document:\n                types::TextDocumentItem {\n                    uri,\n                    text,\n                    version,\n                    language_id,\n                },\n        }: types::DidOpenTextDocumentParams,\n    ) -> Result<()> {\n        let document = TextDocument::new(text, version).with_language_id(language_id);\n\n        session.open_text_document(uri.clone(), document);\n\n        // Publish diagnostics if the client doesn't support pull diagnostics\n        if !session.resolved_client_capabilities().pull_diagnostics {\n            let snapshot = session\n                .take_snapshot(uri.clone())\n                .ok_or_else(|| {\n                    anyhow::anyhow!(\"Unable to take snapshot for document with URI {uri}\")\n                })\n                .with_failure_code(lsp_server::ErrorCode::InternalError)?;\n            publish_diagnostics_for_document(&snapshot, client)?;\n        }\n\n        Ok(())\n    }\n}\n","sourceCodeStart":19,"sourceCodeEnd":46,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_server/src/server/api/notifications/did_open.rs#L19-L46","documentation":"The Ruff LSP server failed to produce a diagnostic snapshot for a document after a `textDocument/didOpen` notification. `take_snapshot` returns None when the URI is not tracked by the session (e.g. the document was never registered or was removed). The server surfaces this as an InternalError response instead of silently skipping diagnostics.","triggerScenarios":"A did_open notification arrives whose URI is not present in the session's document index — e.g. the client opens a document Ruff never saw via workspace/didChangeWatchedFiles initialization, a URI scheme Ruff does not track, or a race where the document was closed before diagnostics were taken.","commonSituations":"VS Code (or another LSP client) with virtual/non-file documents, symlinked or URI-encoded paths that mismatch the index key, multiple workspace folders where the file belongs to an ignored workspace, or client bugs double-sending didOpen after a server restart.","solutions":["Verify the client sends a valid file:// URI in didOpen that matches the URIs used elsewhere (didChange/didClose).","Update ruff-lsp / ruff server to the latest version; several snapshot/URI handling bugs were fixed.","If the document is virtual (untitled, git:, etc.), disable Ruff for those schemes in the client settings.","Restart the language server after workspace folder changes so the document index is rebuilt."],"exampleFix":"// before: sending a non-standard URI from a custom client\n{ \"method\": \"textDocument/didOpen\", \"params\": { \"textDocument\": { \"uri\": \"mem://buffer.py\", ... } } }\n// after: use a file URI the server can index\n{ \"method\": \"textDocument/didOpen\", \"params\": { \"textDocument\": { \"uri\": \"file:///home/user/buffer.py\", ... } } }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// client-side: wrap server dispatch\ntry {\n  await connection.sendNotification('textDocument/didOpen', params);\n} catch (e) {\n  if (String(e.message).includes('Unable to take snapshot')) {\n    console.warn(`Ruff could not index ${params.textDocument.uri}; skipping diagnostics`);\n  }\n}","preventionTips":["Only send didOpen for file:// URIs the server can track.","Keep didOpen/didClose pairing correct to avoid racing the document index.","Restart the server after workspace folder changes.","Keep the ruff server version current."],"tags":["lsp","rust","ruff","diagnostics"],"backgroundTag":"document-not-found","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}