BoundaryML/baml · critical

cannot install the stdlib source root for `{}`: {err}

Error message

cannot install the stdlib source root for `{}`: {err}

What it means

Panic from `install_stdlib` (invoked by `ensure_stdlib_sources` and `ensure_precompiled_stdlib`). Adding one of the stdlib's builtin source roots failed with a `SourceRootError`, which the installer treats as an unrecoverable internal invariant: the embedded stdlib must always be installable.

Source

Thrown at baml_language/crates/baml_db/src/db.rs:495

                // one starts.
                Some(&root) => {
                    assert_eq!(
                        root.interface(self).is_some(),
                        matches!(provenance(package.name), StdlibProvenance::Interface { .. }),
                        "the stdlib root for `{}` is already installed with the other provenance",
                        package.name
                    );
                    root
                }
                None => {
                    let mut spec = SourceRootSpec::new(path, SourceRootKind::Stdlib)
                        .named(Name::new(package.name))
                        .depending_on(dependencies);
                    if let StdlibProvenance::Interface { bytes } = provenance(package.name) {
                        spec = spec.served_from(bytes);
                    }
                    self.add_source_root(spec).unwrap_or_else(|err| {
                        panic!(
                            "cannot install the stdlib source root for `{}`: {err}",
                            package.name
                        )
                    })
                }
            };
            if let StdlibProvenance::Source { files } = provenance(package.name) {
                self.add_or_update_files_in(
                    root,
                    files
                        .iter()
                        .map(|(path, contents)| (path.as_path(), *contents)),
                );
            }
            roots.insert(package.name, root);
        }
        let lang = baml_base::LangPackage::ALL
            .into_iter()

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Install the stdlib (via `ensure_stdlib_sources` or `ensure_precompiled_stdlib`) as the very first operation on a fresh `ProjectDatabase`, before any user roots.
  2. Do not mix source-provenance and interface-provenance stdlib installation on the same database.
  3. If this appears despite correct ordering, it signals a compiler bug — file an issue with the inner error message.

Example fix

// before
let mut db = ProjectDatabase::new();
db.add_source_root(user_root)?; // non-stdlib root installed first
db.ensure_stdlib_sources(); // panics
// after
let mut db = ProjectDatabase::new();
db.ensure_stdlib_sources();
db.add_source_root(user_root)?;
Defensive patterns

Strategy: validation

Validate before calling

fn stdlib_installed_first(db: &ProjectDatabase) -> bool {
    db.roots().iter().all(|r| r.kind() == SourceRootKind::Stdlib)
}

Try / catch

// install_stdlib panics instead of returning Result; guard the ordering invariant before calling.
assert!(stdlib_installed_first(&db), "install stdlib before adding user roots");
db.ensure_stdlib_sources();

Prevention

When it happens

Trigger: `add_source_root` returns any error while installing a stdlib root — e.g. a non-stdlib root already exists at the `<builtin>/<pkg>` path, a dependency edge is rejected, or the root is already installed with the other provenance (the adjacent `assert_eq!` guard).

Common situations: Calling `ensure_stdlib_sources` after another root was added (stdlib must be installed first); mixing `ensure_stdlib_sources` and `ensure_precompiled_stdlib` on the same database; embedding a conflicting path.

Related errors


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