{"record":{"id":"c0b02190c2fbafdd","repo":"astral-sh/ruff","slug":"failed-to-get-the-current-working-directory-while","errorCode":null,"errorMessage":"Failed to get the current working directory while creating a default workspace.","messagePattern":"Failed to get the current working directory while creating a default workspace\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ty_server/src/server.rs","lineNumber":139,"sourceCode":"                    .map(|folder| folder.uri)\n                    .collect::<Vec<_>>()\n            })\n            .or_else(|| {\n                let current_dir = native_system\n                    .current_directory()\n                    .as_std_path()\n                    .to_path_buf();\n                tracing::warn!(\n                    \"No workspace(s) were provided during initialization. \\\n                    Using the current working directory from the fallback system as a \\\n                    default workspace: {}\",\n                    current_dir.display()\n                );\n                let uri = Uri::from_file_path(current_dir).ok()?;\n                Some(vec![uri])\n            })\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Failed to get the current working directory while creating a \\\n                    default workspace.\"\n                )\n            })?;\n\n        Ok(Self {\n            connection,\n            worker_threads,\n            main_loop_receiver,\n            main_loop_sender,\n            session: Session::new(\n                resolved_client_capabilities,\n                position_encoding,\n                workspace_urls,\n                initialization_options,\n                native_system,\n                ClientName::from(client_info),\n                in_test,","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/astral-sh/ruff/blob/672bb4edf04c84f8b0753346359daee4057158f2/crates/ty_server/src/server.rs#L121-L157","documentation":"During the initialize handshake the client provided no workspace folders, so ty falls back to the server process's current working directory as the default workspace. If that directory cannot be determined (fallback system current_dir() is None), initialization fails with this error (server.rs:139).","triggerScenarios":"initialize request with empty/absent workspaceFolders AND no rootUri, while the server process's cwd was deleted, unlinked, or is otherwise unreadable.","commonSituations":"Client spawns ty in a temp directory that is later cleaned up, a wrapper script cd'ing into a removed dir, minimal LSP harnesses that omit workspaceFolders, or a race where the editor deletes the project dir before the server starts.","solutions":["Send workspaceFolders (or rootUri) in the initialize params so no cwd fallback is needed","Ensure the process the server is spawned in has an existing, readable cwd","Restart the editor from the project directory so it inherits a valid cwd"],"exampleFix":"// before\nconst params = { capabilities: clientCaps };  // no workspaceFolders\n\n// after\nconst params = {\n  capabilities: clientCaps,\n  workspaceFolders: [{ uri: rootUri, name: 'my-project' }],\n};","handlingStrategy":"validation","validationCode":"// TS: always provide at least one file workspace folder\nconst workspaceFolders = vscode.workspace.workspaceFolders?.length\n  ? vscode.workspace.workspaceFolders.map(f => ({ uri: f.uri.toString(), name: f.name }))\n  : [{ uri: pathToFileUri(path.resolve('.')), name: 'root' }];\nawait sendRequest('initialize', { capabilities, workspaceFolders });","typeGuard":"const hasFileWorkspace = (folders?: { uri: string }[]): boolean =>\n  !!folders?.some(f => f.uri.startsWith('file:'));","tryCatchPattern":null,"preventionTips":["Never send an initialize without workspaceFolders or rootUri","Don't spawn the server from temp dirs that may be cleaned up mid-session","On initialize failure, check whether the server's cwd still exists"],"tags":["lsp","initialize","workspace","cwd","startup"],"backgroundTag":null,"analyzedSha":"672bb4edf04c84f8b0753346359daee4057158f2","analyzedAt":"2026-08-16T08:54:05.464Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}