BoundaryML/baml · error · LspError
No source root contains {}
Error message
No source root contains {} What it means
LspError::NoRootForPath is returned when a document's path is not under any of the server's known source roots, so the server cannot attribute the file to a workspace/project context. Without a containing root the server cannot resolve project-relative configuration, imports, or generators, so it refuses the request with this error instead of guessing.
Source
Thrown at baml_language/crates/baml_lsp/src/error.rs:38
RequestSerializeError(serde_json::Error),
/// The client's sink is gone; nothing more can be delivered.
#[error("Client closed")]
ClientClosed,
/// Bounded transport backpressure (LSP `RequestFailed`, `-32803`).
#[error("LSP outbound sink is saturated")]
OutboundSaturated,
/// A frame larger than the transport limit (LSP `RequestFailed`,
/// `-32803`).
#[error("LSP outbound frame exceeds the transport limit")]
OutboundOversized,
#[error("Invalid command arguments for command: {command}: {message}")]
InvalidCommandArguments { command: String, message: String },
#[error("File not found: {}", .0.display())]
FileNotFound(PathBuf),
#[error("Path is invalid: {}: {message}", path.display())]
InvalidPath { path: PathBuf, message: String },
/// The document's path is under no known source root.
#[error("No source root contains {}", .0.display())]
NoRootForPath(PathBuf),
/// Cancellation claimed the response while the request was queued or
/// running (LSP `RequestCanceled`, `-32800`).
#[error("Request canceled: {0}")]
RequestCanceled(String),
/// The request's snapshot became stale under an applied source change
/// (LSP `ContentModified`, `-32801`).
#[error("Content modified: {0}")]
ContentModified(String),
/// A valid request that cannot be served right now (LSP `RequestFailed`,
/// `-32803`).
#[error("{0}")]
RequestFailed(String),
/// Violated invariants, panics, serialization (LSP `InternalError`,
/// `-32603`).
#[error("Internal error: {0}")]
Internal(String),
/// Malformed params, position, or range (LSP `InvalidParams`, `-32602`).View on GitHub (pinned to bd85ce9dee)
Solutions
- Open the project's root folder in the editor (not a loose file) so the server registers a workspace folder containing the document.
- Add the file's directory to the workspace folders / multi-root workspace configuration.
- Fix the source-root configuration in the server/client settings so it includes the document's path.
- Move the file inside an existing recognized source root.
Example fix
// before (client init)
workspaceFolders: []
// after
workspaceFolders: [
{ uri: 'file:///home/dev/my-project', name: 'my-project' }
] Defensive patterns
Strategy: validation
Validate before calling
function isUnderRoot(uri, roots) {
const p = new URL(uri).pathname;
return roots.some(r => p.startsWith(new URL(r).pathname));
} Try / catch
try {
await request('textDocument/hover', params);
} catch (e) {
if (e.message?.startsWith('No source root contains')) {
console.warn('Open the containing workspace folder to analyze', params.textDocument.uri);
return null;
}
throw e;
} Prevention
- Always open a project folder, not loose files, when using the BAML LSP
- Keep workspaceFolders populated and accurate in the initialize params
- Verify source-root settings cover every directory containing .baml files
When it happens
Trigger: Opening or requesting analysis for a file located outside all registered workspace folders / source roots; a single-file (detached) editor session with no workspace folder; the source-root configuration excludes the directory containing the file.
Common situations: Editing a .baml file in a scratch directory outside the project; opening a file via symlink whose real path lies outside the workspace; a misconfigured baml source root that points at a subdirectory while files live elsewhere.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- File not found: {}
- Path is invalid: {}: {message}
- Playground server requires either BAML_PLAYGROUND_DEV_PORT o
- Failed to get the current working directory while creating a
- Workspace URL is not a file or directory: {:?}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/a4ecb6ed61b9cf35.
Report an issue: GitHub.