BoundaryML/baml · error

Failed to load project files: {}

Error message

Failed to load project files: {}

What it means

Session::reload reloads all project files into each BamlProject via load_files(); if reading/parsing the project's files fails for any project, reload aborts with 'Failed to load project files'. This wraps the underlying I/O or parse error.

Source

Thrown at engine/language_server/src/session.rs:253

        // Drop moved "baml_src" directories, otherwise the project_updates
        // code below will fail trying to read directories that no longer exist.
        let removed_baml_src_dirs = baml_src_projects
            .keys()
            .filter(|project_root| !project_root.exists())
            .cloned()
            .collect::<Vec<_>>();
        for baml_src_dir in &removed_baml_src_dirs {
            baml_src_projects.remove(baml_src_dir);
        }

        let project_updates: Vec<HashMap<_, _>> = baml_src_projects
            .iter_mut()
            .map(|(project_root, project)| {
                let files_map = project
                    .lock()
                    .baml_project
                    .load_files()
                    .map_err(|e| anyhow::anyhow!("Failed to load project files: {}", e))?;

                tracing::info!(
                    "Loaded {} files for project root: {:?}",
                    files_map.len(),
                    project_root
                );

                {
                    let default_flags = vec!["beta".to_string()];
                    project.lock().update_runtime(
                        notifier.clone(),
                        self.baml_settings
                            .feature_flags
                            .as_ref()
                            .unwrap_or(&default_flags),
                    )
                }
                .map_err(|e| {

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Check the inner error message for the root cause (missing dir vs permissions vs parse)
  2. Restore or recreate the baml_src directory for the affected project root
  3. Fix filesystem permissions so the server process can read the project files
  4. Restart the language server after restoring the project structure

Example fix

// before: project deleted under running server
$ mv baml_src baml_src_backup  # LSP reload fails
// after
$ mv baml_src_backup baml_src  # reload succeeds
Defensive patterns

Strategy: retry

Validate before calling

// pre-check project readability before triggering reload
for (const root of projectRoots) fs.accessSync(path.join(root, 'baml_src'), fs.constants.R_OK);

Type guard

function projectReadable(root: string): boolean { try { fs.accessSync(path.join(root, 'baml_src'), fs.constants.R_OK); return true; } catch { return false; } }

Try / catch

try { await triggerReload(); } catch (e) { if (String(e).includes('Failed to load project files')) { await waitForFsStable(); await triggerReload(); } else throw e; }

Prevention

When it happens

Trigger: load_files() returns Err for a project root: baml_src directory missing/unreadable, permission errors, invalid symlinks, or underlying file parsing failures during a settings/file change triggered reload.

Common situations: baml_src folder renamed or deleted while the LSP is running; project opened on a network mount that went offline; permission changes after a git checkout; workspace with no valid baml_src contents.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/3fdc507318cbd941. Report an issue: GitHub.