{"record":{"id":"d75fb98e3235e26e","repo":"astral-sh/ruff","slug":"workspace-uri-is-not-a-file-path-uri","errorCode":null,"errorMessage":"Workspace URI is not a file path: {uri}","messagePattern":"Workspace URI is not a file path: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ty_server/src/session.rs","lineNumber":800,"sourceCode":"    /// Removes a workspace folder at the given URI.\n    ///\n    /// 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","sourceCodeStart":782,"sourceCodeEnd":818,"githubUrl":"https://github.com/astral-sh/ruff/blob/672bb4edf04c84f8b0753346359daee4057158f2/crates/ty_server/src/session.rs#L782-L818","documentation":"While handling workspace/didChangeWorkspaceFolders (removal), uri.to_file_path() failed for the submitted workspace URI, so ty cannot map the folder to a filesystem path (session.rs:800). Only file-scheme URIs can be converted; untitled:, vscode-virtual:, or other schemes cannot.","triggerScenarios":"Sending a workspace folder removal whose URI is not a `file:` URI — e.g. `untitled:`, a virtual-document scheme, or a remote scheme that lsp-types cannot convert to a path.","commonSituations":"Remote/browser editors forwarding non-file workspaces, extensions adding virtual folders, or clients echoing back URIs the server never registered.","solutions":["Only send removals for `file://` workspace URIs you previously added","Filter workspaceFolders on scheme === 'file' before forwarding to the server","Ignore this error for virtual folders — the server never had them registered"],"exampleFix":"// before\nclient.notify('workspace/didChangeWorkspaceFolders', {\n  event: { removed: [{ uri: 'untitled:Workspace-1', name: 'ws' }] },\n});\n\n// after\nclient.notify('workspace/didChangeWorkspaceFolders', {\n  event: { removed: folders.filter(f => f.uri.startsWith('file:')) },\n});","handlingStrategy":"type-guard","validationCode":"// TS: filter to file URIs before forwarding folder changes\nconst removable = removed.filter(f => f.uri.startsWith('file:'));\nif (removable.length) {\n  client.notify('workspace/didChangeWorkspaceFolders', { event: { removed: removable } });\n}","typeGuard":"const isFileUri = (uri: string): boolean => {\n  try { return vscode.Uri.parse(uri).scheme === 'file'; }\n  catch { return false; }\n};","tryCatchPattern":null,"preventionTips":["Only add/remove `file://` workspace folders; ty rejects everything else","Mirror the server's registry of added folders client-side","Log-and-ignore removal errors for virtual folders — the server never tracked them"],"tags":["lsp","workspace","uri","did-change-workspace-folders"],"backgroundTag":null,"analyzedSha":"672bb4edf04c84f8b0753346359daee4057158f2","analyzedAt":"2026-08-16T08:54:05.464Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}