{"record":{"id":"924d3bf43ea7e6a0","repo":"astral-sh/ruff","slug":"workspace-path-is-not-valid-utf-8","errorCode":null,"errorMessage":"Workspace path is not valid UTF-8: {}","messagePattern":"Workspace path is not valid UTF-8: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ty_server/src/session.rs","lineNumber":802,"sourceCode":"    /// This removes the workspace folder and its associated project database,\n    /// and clears diagnostics for any documents that were in the workspace.\n    ///\n    /// # Errors\n    ///\n    /// This returns an error if the workspace folder has already been removed\n    /// or otherwise could not be found.\n    pub(crate) fn remove_workspace_folder(\n        &mut self,\n        client: &Client,\n        uri: &Uri,\n    ) -> anyhow::Result<()> {\n        tracing::info!(\"Removing workspace folder: {uri}\");\n\n        let path = uri\n            .to_file_path()\n            .map_err(|()| anyhow!(\"Workspace URI is not a file path: {uri}\"))?;\n        let workspace_path = SystemPathBuf::from_path_buf(path)\n            .map_err(|path| anyhow!(\"Workspace path is not valid UTF-8: {}\", path.display()))?;\n\n        anyhow::ensure!(\n            self.workspaces.unregister(&workspace_path),\n            \"Workspace not found: {uri}\",\n        );\n\n        // Note that it is somewhat unclear whether we actually need to\n        // clear diagnostics here. It seems that, at least in the case\n        // of VS Code, it will auto-clear any diagnostics not found in\n        // the workspace diagnostic response. Moreover, VS Code will\n        // re-request workspace diagnostics after removing a workspace\n        // folder.\n        //\n        // For now, we keep unconditionally clearing diagnostics on\n        // opened text documents for reasons of good sense, but it's\n        // possible that we don't even need to do that (when workspace\n        // diagnostics are enabled).\n        //","sourceCodeStart":784,"sourceCodeEnd":820,"githubUrl":"https://github.com/astral-sh/ruff/blob/672bb4edf04c84f8b0753346359daee4057158f2/crates/ty_server/src/session.rs#L784-L820","documentation":"During workspace folder removal, the URI did convert to a path, but the resulting OS path contains bytes that are not valid UTF-8; SystemPathBuf::from_path_buf fails (session.rs:802). ty only stores Unicode paths, mirroring the startup check in lib.rs.","triggerScenarios":"Removing a workspace folder whose decoded filesystem path holds non-UTF-8 bytes — e.g. a legacy-encoded directory name on Linux being removed by an editor that received it from a file-watcher.","commonSituations":"Projects under locale-encoded (Latin-1/Shift-JIS) directories, non-UTF-8 filenames surfaced by git or package managers, or URIs percent-encoded from raw non-UTF-8 bytes.","solutions":["Rename the directory to a UTF-8 name, then re-add/remove the folder","Ensure the environment locale is UTF-8 so editors produce UTF-8 URIs","Avoid adding non-UTF-8 workspaces in the first place (the add path fails the same way)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// TS: reject non-UTF-8-decodable paths before sending folder changes\nconst isUtf8Path = (uri: string): boolean =>\n  !decodeURIComponent(uri).includes('\\uFFFD');\nif (isUtf8Path(uri)) removeFolder(uri);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep project directories entirely UTF-8 named","Run under a UTF-8 locale so URIs are generated from UTF-8 bytes","Never synthesize folder URIs from raw OS paths of unknown encoding"],"tags":["lsp","workspace","uri","unicode","encoding"],"backgroundTag":null,"analyzedSha":"672bb4edf04c84f8b0753346359daee4057158f2","analyzedAt":"2026-08-16T08:54:05.464Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}