BoundaryML/baml · error · SourceRootError
dependency ` ` names a source root that does not exist
Error message
dependency `{name}` names a source root that does not exist What it means
Part of `SourceRootError` returned by `ProjectDatabase::add_source_root` / `add_dependency`. A dependency edge references a root `name` that is not a live source root in the database. Dependency edges must point at roots that have already been added.
Solutions
- Add the dependency target's source root first (dependency order), then add the dependent root.
- Verify the dependency name matches an existing root exactly (spelling/case).
- If the target was removed, drop or update the stale dependency edge.
Example fix
// before
db.add_source_root(app_spec.depending_on(vec![Dependency { name: "core".into(), .. }]))?; // core not added yet
// after
db.add_source_root(core_spec)?;
db.add_source_root(app_spec.depending_on(vec![Dependency { name: "core".into(), .. }]))?; Defensive patterns
Strategy: validation
Validate before calling
fn deps_exist(deps: &[Dependency], db: &ProjectDatabase) -> Result<(), String> {
for d in deps {
if db.find_source_root(&d.name).is_none() {
return Err(format!("dependency `{}` is not a live root", d.name));
}
}
Ok(())
} Try / catch
match db.add_source_root(spec) {
Err(SourceRootError::UnknownDependencyRoot { name }) => eprintln!("add root `{name}` first"),
Err(e) => eprintln!("root error: {e}"),
Ok(root) => root,
} Prevention
- Always install dependency targets before dependents (topological order).
- Verify dependency names against the live root list before wiring edges.
- Avoid deleting roots while others reference them.
When it happens
Trigger: Calling `add_source_root` with `depending_on` where a `Dependency.root` name (or the referenced root) does not correspond to any root currently registered via `add_source_root`.
Common situations: Adding a project root that depends on another package before that package's root is installed; typos in dependency names; removing a root while other roots still depend on it.
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
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/c9019a5740db8211.
Report an issue: GitHub.
Appendix: source
Thrown at baml_language/crates/baml_db/src/db.rs:97
}
/// Why [`ProjectDatabase::add_source_root`] or
/// [`ProjectDatabase::add_dependency`] refused.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum SourceRootError {
/// A live root already sits at this (canonical) path.
#[error("a source root already exists at this path")]
PathTaken(SourceRoot),
/// The edge name is one no package may declare: a stdlib package's name
/// (already an implicit edge of every package) or a source-level
/// qualifier (`root`, `env`).
#[error("dependency name `{name}` is reserved")]
ReservedDependencyName { name: Name },
/// The root already has an edge under this name.
#[error("dependency `{name}` is declared twice")]
DuplicateDependencyName { name: Name },
/// The edge names a root that is not live in this database.
#[error("dependency `{name}` names a source root that does not exist")]
UnknownDependencyRoot { name: Name },
/// The edge would make the dependency graph cyclic.
#[error("dependency `{name}` would form a dependency cycle")]
DependencyCycle { name: Name },
/// The interface bytes are not a valid `PackageInterface` artifact.
#[error("invalid package interface: {message}")]
InvalidInterface { message: String },
}
/// The main database for BAML projects.
///
/// `ProjectDatabase` owns the Salsa storage directly and implements all the
/// compiler `Db` traits. It provides high-level APIs for:
/// - Source-root management (add/remove roots, longest-prefix lookup)
/// - File management within a root (add/update/remove files)
/// - Diagnostics collection via `check()`
///
/// ## ExampleView on GitHub (pinned to bd85ce9dee)