{"record":{"id":"6917c4af367e8ce0","repo":"astral-sh/ruff","slug":"tried-to-close-unavailable-document-key","errorCode":null,"errorMessage":"Tried to close unavailable document `{key}`","messagePattern":"Tried to close unavailable document `(.+?)`","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/ruff_server/src/session/index.rs","lineNumber":327,"sourceCode":"        }\n        self.documents\n            .insert(notebook_uri, DocumentController::new_notebook(document));\n    }\n\n    pub(super) fn close_document(&mut self, key: &DocumentKey) -> crate::Result<()> {\n        // Notebook cells URIs are removed from the index here, instead of during\n        // `update_notebook_document`. This is because a notebook cell, as a text document,\n        // is requested to be `closed` by VS Code after the notebook gets updated.\n        // This is not documented in the LSP specification explicitly, and this assumption\n        // may need revisiting in the future as we support more editors with notebook support.\n        if let DocumentKey::NotebookCell(uri) = key {\n            if self.notebook_cells.remove(uri).is_none() {\n                tracing::warn!(\"Tried to remove a notebook cell that does not exist: {uri}\",);\n            }\n            return Ok(());\n        }\n        let Some(uri) = self.uri_for_key(key).cloned() else {\n            anyhow::bail!(\"Tried to close unavailable document `{key}`\");\n        };\n\n        let Some(_) = self.documents.remove(&uri) else {\n            anyhow::bail!(\"tried to close document that didn't exist at {uri}\")\n        };\n        Ok(())\n    }\n\n    pub(super) fn client_settings(&self, key: &DocumentKey) -> Option<Arc<ClientSettings>> {\n        let uri = self.uri_for_key(key)?;\n        let WorkspaceSettings {\n            client_settings, ..\n        } = self.settings_for_uri(uri)?;\n        Some(client_settings.clone())\n    }\n\n    fn document_controller_for_key(\n        &mut self,","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/astral-sh/ruff/blob/672bb4edf04c84f8b0753346359daee4057158f2/crates/ruff_server/src/session/index.rs#L309-L345","documentation":"Error \"Tried to close unavailable document `{key}`\" thrown in astral-sh/ruff.","triggerScenarios":"Thrown at crates/ruff_server/src/session/index.rs:327 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"672bb4edf04c84f8b0753346359daee4057158f2","analyzedAt":"2026-08-16T08:54:05.464Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}