BoundaryML/baml · error
Failed to get the current working directory while creating a
Error message
Failed to get the current working directory while creating a default workspace.
What it means
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.
Source
Thrown at engine/language_server/src/server.rs:162
.map(|folders| folders.into_iter().filter_map(|folder| {
let baml_src_dir = find_baml_src(&PathBuf::from(folder.uri.path()))?;
let baml_src_uri = Url::from_file_path(baml_src_dir.to_str()?).ok()?;
Some(workspace_for_url(baml_src_uri))
}).collect())
.or_else(|| {
tracing::warn!("No workspace(s) were provided during initialization. Using the current working directory as a default workspace...");
let pwd = std::env::current_dir().ok()?;
if pwd.ends_with("baml_src") {
let url = Url::from_file_path(pwd).expect("PWD should be valid");
Some(vec![workspace_for_url(url)])
} else {
let baml_src_dir = find_top_level_parent(&std::env::current_dir().ok()?)?;
let uri = Url::from_file_path(baml_src_dir).ok()?;
Some(vec![workspace_for_url(uri)])
}
})
.ok_or_else(|| {
anyhow::anyhow!("Failed to get the current working directory while creating a default workspace.")
})?;
tracing::info!(
"Starting language server: worker_threads={}, version={}, playground=http://localhost:{}, proxy=http://localhost:{}",
worker_threads,
env!("CARGO_PKG_VERSION"),
args.playground_port,
args.proxy_port
);
let rt = tokio::runtime::Runtime::new()?;
// Extract client version from initialization parameters
let client_version = init_params
.client_info
.as_ref()
.and_then(|info| info.version.clone());
View on GitHub (pinned to bd85ce9dee)
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
Example fix
// before (spawning server with no cwd)
Command::new("baml-lsp").spawn()
// after
let cwd = std::env::current_dir()?;
Command::new("baml-lsp").current_dir(cwd).spawn() Defensive patterns
Strategy: fallback
Validate before calling
// caller-side check before launching
if (process.cwd() === undefined || !fs.existsSync(process.cwd())) throw new Error('no valid cwd'); Type guard
function hasValidCwd(): boolean { try { return !!process.cwd() && fs.existsSync(process.cwd()); } catch { return false; } } Try / catch
try { await startLanguageServer(); } catch (e) { if (String(e).includes('current working directory')) await startLanguageServer({ cwd: projectRoot }); else throw e; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- Workspace URL is not a file or directory: {:?}
- {0}
- Notification not supported: {0}
- Request not supported: {0}
- Failed to serialize request result: {0}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/b9222835f72b80ff.
Report an issue: GitHub.