{"record":{"id":"8b0b4cc6f74d226d","repo":"BoundaryML/baml","slug":"two-targets-share-subcommand-name-and-subcommand-names-come","errorCode":null,"errorMessage":"two targets share subcommand name `{}` (`{}` and `{}`). Subcommand names come from the last `.`-segment of the function name; rename one of them so the binary's subcommands stay unambiguous.","messagePattern":"two targets share subcommand name `(.+?)` \\(`(.+?)` and `(.+?)`\\)\\. Subcommand names come from the last `\\.`-segment of the function name; rename one of them so the binary's subcommands stay unambiguous\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/pack_command.rs","lineNumber":399,"sourceCode":"    /// layer per the spec).\n    fn resolve_targets(\n        &self,\n        engine: &BexEngine,\n    ) -> Result<(baml_exec::PackMode, Vec<ResolvedPackTarget>)> {\n        if let Some(target) = self.target.as_deref() {\n            let resolved = resolve_one(engine, target)?;\n            return Ok((baml_exec::PackMode::Single, vec![resolved]));\n        }\n\n        // Subcommand mode. Resolve each `-f` and reject duplicate subcommand names.\n        let mut resolved: Vec<ResolvedPackTarget> = Vec::with_capacity(self.functions.len());\n        for func in &self.functions {\n            resolved.push(resolve_one(engine, func)?);\n        }\n        let mut seen: HashMap<&str, &str> = HashMap::new();\n        for r in &resolved {\n            if let Some(prev) = seen.insert(r.subcommand_name.as_str(), r.display_name.as_str()) {\n                anyhow::bail!(\n                    \"two targets share subcommand name `{}` (`{}` and `{}`). \\\n                     Subcommand names come from the last `.`-segment of the function name; \\\n                     rename one of them so the binary's subcommands stay unambiguous.\",\n                    r.subcommand_name,\n                    prev,\n                    r.display_name,\n                );\n            }\n        }\n        Ok((baml_exec::PackMode::Subcommand, resolved))\n    }\n\n    /// Pick the default output basename.\n    ///\n    /// - `--file <PATH>` single-file mode: file stem (e.g. `foo.baml` →\n    ///   `foo`). `baml.toml` isn't consulted — single-file packs are\n    ///   intentionally hermetic.\n    /// - Project mode: `[package].name` from `<from>/baml.toml` when a","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/pack_command.rs#L381-L417","documentation":"resolve_targets checks that every resolved pack target has a unique subcommand name, derived from the last `.`-segment of the function's qualified name (e.g. `user.Foo` and `admin.Foo` both yield `Foo`). If two `-f` targets collide, the packed subcommand binary would have ambiguous subcommands, so the CLI bails naming both full function names.","triggerScenarios":"Running `baml pack -f ns1.MyFunc -f ns2.MyFunc` (or two unqualified names resolving to functions in different modules) where both functions share the same final segment.","commonSituations":"Packing same-named functions defined in different BAML modules/namespaces; renaming a module without noticing a name collision; auto-generating `-f` lists from scripts that collect qualified names.","solutions":["Rename one of the colliding functions (or move it so its last `.`-segment differs) in the `.baml` source.","Pack fewer functions — drop one of the colliding `-f` targets.","Pack each colliding function as a separate single-entry binary using the positional target instead."],"exampleFix":"// before\nbaml pack -f user.Greet -f admin.Greet\n\n// after (rename one function in source)\nbaml pack -f user.Greet -f admin.AdminGreet","handlingStrategy":"validation","validationCode":"# ensure unique last segments among -f targets\nNAMES=\"user.Greet admin.Greet\"\ndups=$(echo \"$NAMES\" | tr ' ' '\\n' | awk -F. '{print $NF}' | sort | uniq -d)\n[ -n \"$dups\" ] && { echo \"colliding subcommand names: $dups\" >&2; exit 2; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give functions unique final name segments across modules you pack together.","Check planned `-f` lists for duplicate last segments before packing.","Prefer distinct top-level names for functions intended as subcommands."],"tags":["cli","naming-conflict","baml-pack"],"backgroundTag":"invalid-argument-value","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}