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

Workspace not found

Error message

Workspace not found: {uri}

What it means

An anyhow error raised while removing a workspace folder: the URI was converted to a path successfully, but no registered workspace matches it — typically because it was already removed or never added. Distinct from the URI/UTF-8 conversion errors raised just before it.

Solutions

  1. Remove the folder only once and after it was added
  2. Check the registered workspace list before issuing didChangeWorkspaceFolders removals
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/ty_server/src/session.rs:990 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of astral-sh/ruff@5bb508f594 (2026-09-05). Data as JSON: /api/errors/448eef05be31aa27. Report an issue: GitHub.

Appendix: source

Thrown at crates/ty_server/src/session.rs:998

    ///
    /// # Errors
    ///
    /// This returns an error if the workspace folder has already been removed
    /// or otherwise could not be found.
    pub(crate) fn remove_workspace_folder(
        &mut self,
        client: &Client,
        uri: &Uri,
    ) -> anyhow::Result<()> {
        tracing::info!("Removing workspace folder: {uri}");

        let path = uri
            .to_file_path()
            .map_err(|()| anyhow!("Workspace URI is not a file path: {uri}"))?;
        let workspace_path = SystemPathBuf::from_path_buf(path)
            .map_err(|path| anyhow!("Workspace path is not valid UTF-8: {}", path.display()))?;

        anyhow::ensure!(
            self.workspaces.unregister(&workspace_path),
            "Workspace not found: {uri}",
        );

        // Note that it is somewhat unclear whether we actually need to
        // clear diagnostics here. It seems that, at least in the case
        // of VS Code, it will auto-clear any diagnostics not found in
        // the workspace diagnostic response. Moreover, VS Code will
        // re-request workspace diagnostics after removing a workspace
        // folder.
        //
        // For now, we keep unconditionally clearing diagnostics on
        // opened text documents for reasons of good sense, but it's
        // possible that we don't even need to do that (when workspace
        // diagnostics are enabled).
        //
        // See: https://github.com/astral-sh/ruff/pull/22953#discussion_r2745255350

View on GitHub (pinned to 5bb508f594)