{"record":{"id":"a1a879eb77d5eff8","repo":"BoundaryML/baml","slug":"compilation-failed-e-pack-command","errorCode":null,"errorMessage":"compilation failed: {e:?}","messagePattern":"compilation failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/pack_command.rs","lineNumber":275,"sourceCode":"        }\n        Ok(())\n    }\n\n    fn resolved_target_triple(&self) -> Result<&str> {\n        match self.target_triple.as_deref() {\n            Some(target) => validate_release_target_triple(target),\n            None => release_host_target_triple(),\n        }\n    }\n\n    fn load_and_compile(&self, reporter: &Reporter) -> Result<(ProjectDatabase, Program, bool)> {\n        if let Some(file) = self.file.as_deref() {\n            // Standalone `--file` mode has no project root, so there is no\n            // cache seam — always a cold compile, same as `baml run --file`.\n            let (db, package, needs_format_hint) = self.load_standalone(file)?;\n            check_diagnostics(&db, \"cannot pack: compilation errors found\", reporter)?;\n            let program = baml_compiler2_emit::generate_project_bytecode(&db, package)\n                .map_err(|e| anyhow!(\"compilation failed: {e:?}\"))?;\n            return Ok((db, program, needs_format_hint));\n        }\n        self.load_and_compile_project(reporter)\n    }\n\n    /// Project-mode load + compile through the bytecode cache — the same warm\n    /// flow as `baml run` (`run_command::load_and_compile`): whole-program hit\n    /// when nothing changed, per-file unit reuse on a dirty edit, full compile\n    /// otherwise. Pack shares run/check's exact cache key space, so a pack\n    /// right after a run (or a\n    /// re-pack) serves the identical `Program`. The packaged bytecode is\n    /// target-independent (the `--target` triple only selects the host binary\n    /// bytes), and emit determinism guarantees a reused image is byte-identical\n    /// to a fresh compile, so serving from cache never changes the artifact.\n    fn load_and_compile_project(\n        &self,\n        reporter: &Reporter,\n    ) -> Result<(ProjectDatabase, Program, bool)> {","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/pack_command.rs#L257-L293","documentation":"In standalone `--file` mode, `baml pack` compiles the single BAML file with baml_compiler2_emit::generate_project_bytecode; if code generation (or compilation) returns an error, it is wrapped with anyhow! as `compilation failed: {e:?}`. This is the CLI's way of reporting that the file could not be turned into bytecode, distinct from diagnostics-level compile errors (which check_diagnostics reports first).","triggerScenarios":"Running `baml pack --file <path>` where the file parses cleanly enough to pass check_diagnostics but generate_project_bytecode still fails (e.g. internal codegen errors on constructs it cannot lower).","commonSituations":"Packing a standalone .baml file that uses a feature the bytecode emitter does not yet support; a compiler bug triggered by unusual code; version mismatch between CLI and compiler crates in a local build.","solutions":["Read the wrapped `{e:?}` detail to identify the failing construct and simplify or fix it in the source file.","Fix any diagnostics first with `baml check --file <path>` to rule out ordinary compile errors.","Update the baml CLI/compiler to matching latest versions and retry.","If the source looks valid, file a bug with the debug-formatted error and a minimal repro file."],"exampleFix":"// before\nbaml pack --file broken.baml   // compilation failed: <codegen error>\n\n// after: check first, fix the reported construct, then pack\nbaml check --file broken.baml\nbaml pack --file broken.baml","handlingStrategy":"try-catch","validationCode":"# run a check-only compile first\nbaml check --file path/to/file.baml","typeGuard":null,"tryCatchPattern":"match baml_pack_standalone(file) {\n    Err(e) if e.to_string().starts_with(\"compilation failed\") => {\n        eprintln!(\"codegen failed: {e:#}\");\n        // report bug or adjust source\n    }\n    Err(e) => return Err(e),\n    Ok(out) => /* proceed */ (),\n}","preventionTips":["Always run `baml check --file` before `baml pack --file`.","Keep the CLI and compiler crates at matching versions.","Avoid relying on undocumented language constructs that may not lower to bytecode yet."],"tags":["cli","compilation","codegen","baml-pack"],"backgroundTag":"unsupported-operation","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"}