{"record":{"id":"3621373e38d4b522","repo":"BoundaryML/baml","slug":"dependency-name-is-declared-twice","errorCode":null,"errorMessage":"dependency `{name}` is declared twice","messagePattern":"dependency `(.+?)` is declared twice","errorType":"exception","errorClass":"SourceRootError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_db/src/db.rs","lineNumber":94,"sourceCode":"        self.dependencies = dependencies;\n        self\n    }\n}\n\n/// Why [`ProjectDatabase::add_source_root`] or\n/// [`ProjectDatabase::add_dependency`] refused.\n#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]\npub enum SourceRootError {\n    /// A live root already sits at this (canonical) path.\n    #[error(\"a source root already exists at this path\")]\n    PathTaken(SourceRoot),\n    /// The edge name is one no package may declare: a stdlib package's name\n    /// (already an implicit edge of every package) or a source-level\n    /// qualifier (`root`, `env`).\n    #[error(\"dependency name `{name}` is reserved\")]\n    ReservedDependencyName { name: Name },\n    /// The root already has an edge under this name.\n    #[error(\"dependency `{name}` is declared twice\")]\n    DuplicateDependencyName { name: Name },\n    /// The edge names a root that is not live in this database.\n    #[error(\"dependency `{name}` names a source root that does not exist\")]\n    UnknownDependencyRoot { name: Name },\n    /// The edge would make the dependency graph cyclic.\n    #[error(\"dependency `{name}` would form a dependency cycle\")]\n    DependencyCycle { name: Name },\n    /// The interface bytes are not a valid `PackageInterface` artifact.\n    #[error(\"invalid package interface: {message}\")]\n    InvalidInterface { message: String },\n}\n\n/// The main database for BAML projects.\n///\n/// `ProjectDatabase` owns the Salsa storage directly and implements all the\n/// compiler `Db` traits. It provides high-level APIs for:\n/// - Source-root management (add/remove roots, longest-prefix lookup)\n/// - File management within a root (add/update/remove files)","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_db/src/db.rs#L76-L112","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","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."],"exampleFix":"// before\nspec.depending_on(vec![dep(\"core\"), dep(\"core\")])\n// after\nlet mut seen = HashSet::new();\nlet deps: Vec<Dependency> = deps.into_iter().filter(|d| seen.insert(d.name.clone())).collect();\nspec.depending_on(deps)","handlingStrategy":"validation","validationCode":"fn ensure_unique_names(deps: &[Dependency]) -> Result<(), String> {\n    let mut seen = std::collections::HashSet::new();\n    for d in deps {\n        if !seen.insert(&d.name) { return Err(format!(\"duplicate dependency `{}`\", d.name)); }\n    }\n    Ok(())\n}","typeGuard":"fn has_unique_names(deps: &[Dependency]) -> bool {\n    deps.iter().map(|d| &d.name).collect::<std::collections::HashSet<_>>().len() == deps.len()\n}","tryCatchPattern":"match db.add_source_root(spec) {\n    Err(SourceRootError::DuplicateDependencyName { name }) => eprintln!(\"fix duplicate edge `{name}`\"),\n    Err(e) => eprintln!(\"other root error: {e}\"),\n    Ok(root) => root,\n}","preventionTips":["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."],"tags":["dependency-management","rust","duplicate-key"],"backgroundTag":"conflicting-config-options","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}