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

Workspace path is not valid UTF-8

Error message

Workspace path is not valid UTF-8: {}

What it means

An anyhow error raised while removing a workspace folder: the folder's URI converted to a file path, but the resulting path is not valid UTF-8. ty only supports Unicode paths, so the folder cannot be matched against known workspaces.

Solutions

  1. Ensure workspace folder URIs use Unicode paths
  2. Re-open the workspace from a valid UTF-8 path
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/ty_server/src/session.rs:988 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/924d3bf43ea7e6a0. Report an issue: GitHub.

Appendix: source

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

    /// This removes the workspace folder and its associated project database,
    /// and clears diagnostics for any documents that were in the workspace.
    ///
    /// # 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).
        //

View on GitHub (pinned to 5bb508f594)