{"record":{"id":"b9222835f72b80ff","repo":"BoundaryML/baml","slug":"failed-to-get-the-current-working-directory-while-creating-a","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":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_server/src/server.rs","lineNumber":162,"sourceCode":"            .map(|folders| folders.into_iter().filter_map(|folder| {\n                let baml_src_dir = find_baml_src(&PathBuf::from(folder.uri.path()))?;\n                let baml_src_uri = Url::from_file_path(baml_src_dir.to_str()?).ok()?;\n                Some(workspace_for_url(baml_src_uri))\n            }).collect())\n            .or_else(|| {\n                tracing::warn!(\"No workspace(s) were provided during initialization. Using the current working directory as a default workspace...\");\n                let pwd = std::env::current_dir().ok()?;\n                if pwd.ends_with(\"baml_src\") {\n                    let url = Url::from_file_path(pwd).expect(\"PWD should be valid\");\n                    Some(vec![workspace_for_url(url)])\n                } else {\n                    let baml_src_dir = find_top_level_parent(&std::env::current_dir().ok()?)?;\n                    let uri = Url::from_file_path(baml_src_dir).ok()?;\n                    Some(vec![workspace_for_url(uri)])\n                }\n            })\n            .ok_or_else(|| {\n                anyhow::anyhow!(\"Failed to get the current working directory while creating a default workspace.\")\n            })?;\n\n        tracing::info!(\n            \"Starting language server: worker_threads={}, version={}, playground=http://localhost:{}, proxy=http://localhost:{}\",\n            worker_threads,\n            env!(\"CARGO_PKG_VERSION\"),\n            args.playground_port,\n            args.proxy_port\n        );\n\n        let rt = tokio::runtime::Runtime::new()?;\n\n        // Extract client version from initialization parameters\n        let client_version = init_params\n            .client_info\n            .as_ref()\n            .and_then(|info| info.version.clone());\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_server/src/server.rs#L144-L180","documentation":"Thrown by the BAML language server when it starts without any workspace folders from the client and must create a default workspace rooted at the current working directory. If std::env::current_dir() fails (or the resulting path cannot be converted to a URL), no default workspace can be built, so new_with_connection aborts with this anyhow error.","triggerScenarios":"Launching the language server in an environment where the process has no current working directory (deleted cwd, restricted sandbox, some daemonized/container launches) and the client sent no workspace folders or none resolved via find_top_level_parent.","commonSituations":"Running the LSP from a directory that was deleted; spawning the server with cwd unset; containers/systemd services started with / deleted or /proc restrictions; running via an editor plugin that omits workspaceFolders on initialized.","solutions":["Restart the language server from a valid, existing working directory (cd into your project first)","Ensure the editor plugin sends workspaceFolders / rootUri during initialization","If running the server manually, verify `pwd` works in the same environment before launching","Check container/sandbox config so the process inherits a valid cwd"],"exampleFix":"// before (spawning server with no cwd)\nCommand::new(\"baml-lsp\").spawn()\n// after\nlet cwd = std::env::current_dir()?;\nCommand::new(\"baml-lsp\").current_dir(cwd).spawn()","handlingStrategy":"fallback","validationCode":"// caller-side check before launching\nif (process.cwd() === undefined || !fs.existsSync(process.cwd())) throw new Error('no valid cwd');","typeGuard":"function hasValidCwd(): boolean { try { return !!process.cwd() && fs.existsSync(process.cwd()); } catch { return false; } }","tryCatchPattern":"try { await startLanguageServer(); } catch (e) { if (String(e).includes('current working directory')) await startLanguageServer({ cwd: projectRoot }); else throw e; }","preventionTips":["Always launch the LSP with an explicit existing cwd","Verify the directory exists before spawning","Ensure the plugin sends workspaceFolders during initialize","Avoid daemonizing from a deleted directory"],"tags":["lsp","workspace","rust","startup"],"backgroundTag":"missing-env-var","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}