BoundaryML/baml · error · SourceRootError
dependency ` ` is declared twice
Error message
dependency `{name}` is declared twice What it means
Part of the `SourceRootError` enum returned by `ProjectDatabase::add_source_root` / `add_dependency`. Thrown when the same dependency edge name is declared more than once on a single source root. Each package may have at most one edge per name; a second declaration is ambiguous and rejected.
Solutions
- Deduplicate the `Vec<Dependency>` passed to `depending_on`, keeping one entry per `name`.
- If two edges intentionally differ, give one a different alias `name`.
- Check the manifest/source that produced the spec for repeated dependency entries.
Example fix
// before
spec.depending_on(vec![dep("core"), dep("core")])
// after
let mut seen = HashSet::new();
let deps: Vec<Dependency> = deps.into_iter().filter(|d| seen.insert(d.name.clone())).collect();
spec.depending_on(deps) Defensive patterns
Strategy: validation
Validate before calling
fn ensure_unique_names(deps: &[Dependency]) -> Result<(), String> {
let mut seen = std::collections::HashSet::new();
for d in deps {
if !seen.insert(&d.name) { return Err(format!("duplicate dependency `{}`", d.name)); }
}
Ok(())
} Type guard
fn has_unique_names(deps: &[Dependency]) -> bool {
deps.iter().map(|d| &d.name).collect::<std::collections::HashSet<_>>().len() == deps.len()
} Try / catch
match db.add_source_root(spec) {
Err(SourceRootError::DuplicateDependencyName { name }) => eprintln!("fix duplicate edge `{name}`"),
Err(e) => eprintln!("other root error: {e}"),
Ok(root) => root,
} Prevention
- Deduplicate dependency lists before building the SourceRootSpec.
- Centralize spec construction in one helper that enforces unique names.
- Add a unit test asserting spec builders never emit duplicate names.
When it happens
Trigger: Calling `add_source_root` (or `add_dependency`) with a `SourceRootSpec` built via `depending_on` where two `Dependency` entries in the vector share the same `name`.
Common situations: Hand-written dependency lists built programmatically that append a name twice; manifest/tooling generation bugs that emit duplicate edges; merging two dependency lists without deduplication.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- dependency ` ` names a source root that does not exist
- dependency ` ` would form a dependency cycle
- {0}
- {0}
- {0}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/3621373e38d4b522.
Report an issue: GitHub.
Appendix: source
Thrown at baml_language/crates/baml_db/src/db.rs:94
self.dependencies = dependencies;
self
}
}
/// 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)View on GitHub (pinned to bd85ce9dee)