BoundaryML/baml · error · anyhow::Error
Failed to gather files from directory
Error message
Failed to gather files from directory {}: {} What it means
BamlProject.load_files wraps gather_files() failures in this message, which includes the project root directory and the underlying error. It means the language server could not enumerate the BAML/workspace files under root_dir_name, so the project state cannot be loaded. Typically the root directory is missing, inaccessible, or unreadable.
Solutions
- Verify the workspace root directory passed at initialization exists and is readable (ls it from the same user the LSP runs as)
- Reopen/restart the editor session so the LSP re-initializes with the correct root_uri
- Fix directory permissions (chmod/chown) or move the project back to the expected path
- Update any configured workspace root path to the current project location
Example fix
// before
lsp.initialize({ rootUri: "file:///home/me/old-project" });
// after
lsp.initialize({ rootUri: "file:///home/me/current-project" }); Defensive patterns
Strategy: validation
Validate before calling
use std::path::Path;
fn ensure_root_readable(root: &Path) -> std::io::Result<()> {
let meta = std::fs::metadata(root)?;
if !meta.is_dir() {
return Err(std::io::Error::new(std::io::ErrorKind::Other, "root is not a directory"));
}
std::fs::read_dir(root).map(|_| ())
} Try / catch
match project.load_files() {
Err(e) if e.to_string().starts_with("Failed to gather files") => {
eprintln!("Workspace root missing/unreadable: {e}");
// prompt user to re-initialize with correct root
}
r => r,
} Prevention
- Validate the workspace root exists and is readable before initializing the LSP/project
- Avoid pointing the project at network mounts or removable drives that can disappear
- Re-initialize editor sessions after moving or renaming the project directory
When it happens
Trigger: load_files() called when the project root directory does not exist, was deleted or renamed, lacks read permission, or when the filesystem walk (gather_files) fails with an I/O error.
Common situations: LSP client sending a didOpen/initialize with a stale workspace root path; project checked out to a different location; symlinked or network-mounted directories that are unavailable; permission changes after checkout.
Related errors
- Failed to read file
- a source root already exists at this path
- BAML Generate failed - Project has errors.
- blob path has no parent
- cannot determine directory of current executable
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/1e3ef118f9017bba.
Report an issue: GitHub.
Appendix: source
Thrown at engine/language_server/src/baml_project/mod.rs:270
pub fn update_file(&mut self, document_key: &DocumentKey, content: Option<String>) {
tracing::debug!(
"Updating file: {}, {}",
document_key.path().display(),
content.clone().unwrap_or("None".to_string())
);
if let Some(content) = content {
let text_document = TextDocument::new(content, 0);
self.files.insert(document_key.clone(), text_document);
} else {
self.files.remove(document_key);
}
self.cached_runtime = None;
}
/// Load files into the current state. Also return the newly loaded files.
pub fn load_files(&mut self) -> anyhow::Result<HashMap<DocumentKey, TextDocument>> {
let workspace_file_paths = gather_files(&self.root_dir_name, false).map_err(|e| {
anyhow::anyhow!(
"Failed to gather files from directory {}: {}",
self.root_dir_name.display(),
e
)
})?;
let workspace_files = workspace_file_paths
.into_iter()
.map(|file_path| {
let document_key = DocumentKey::from_path(&self.root_dir_name, &file_path)
.map_err(|e| {
anyhow::anyhow!(
"Failed to create document key for file {}: {}",
file_path.display(),
e
)
})?;
let contents = std::fs::read_to_string(&file_path).map_err(|e| {
anyhow::anyhow!("Failed to read file {}: {}", file_path.display(), e)View on GitHub (pinned to bd85ce9dee)