astral-sh/ruff · error · anyhow::Error

tried to close document that didn't exist at {uri}

Error message

tried to close document that didn't exist at {uri}

What it means

Error "tried to close document that didn't exist at {uri}" thrown in astral-sh/ruff.

Source

Thrown at crates/ruff_server/src/session/index.rs:331

    pub(super) fn close_document(&mut self, key: &DocumentKey) -> crate::Result<()> {
        // Notebook cells URIs are removed from the index here, instead of during
        // `update_notebook_document`. This is because a notebook cell, as a text document,
        // is requested to be `closed` by VS Code after the notebook gets updated.
        // This is not documented in the LSP specification explicitly, and this assumption
        // may need revisiting in the future as we support more editors with notebook support.
        if let DocumentKey::NotebookCell(uri) = key {
            if self.notebook_cells.remove(uri).is_none() {
                tracing::warn!("Tried to remove a notebook cell that does not exist: {uri}",);
            }
            return Ok(());
        }
        let Some(uri) = self.uri_for_key(key).cloned() else {
            anyhow::bail!("Tried to close unavailable document `{key}`");
        };

        let Some(_) = self.documents.remove(&uri) else {
            anyhow::bail!("tried to close document that didn't exist at {uri}")
        };
        Ok(())
    }

    pub(super) fn client_settings(&self, key: &DocumentKey) -> Option<Arc<ClientSettings>> {
        let uri = self.uri_for_key(key)?;
        let WorkspaceSettings {
            client_settings, ..
        } = self.settings_for_uri(uri)?;
        Some(client_settings.clone())
    }

    fn document_controller_for_key(
        &mut self,
        key: &DocumentKey,
    ) -> crate::Result<&mut DocumentController> {
        let Some(uri) = self.uri_for_key(key).cloned() else {
            anyhow::bail!("Tried to open unavailable document `{key}`");

View on GitHub (pinned to 672bb4edf0)

When it happens

Trigger: Thrown at crates/ruff_server/src/session/index.rs:331 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of astral-sh/ruff@672bb4edf0 (2026-08-16). Data as JSON: /api/errors/7b1a8974b74de6d2. Report an issue: GitHub.