{"record":{"id":"1ef50c989a96263a","repo":"BoundaryML/baml","slug":"compilation-failed-e-run-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/run_command.rs","lineNumber":359,"sourceCode":"            .collect();\n        if errors.is_empty() {\n            return Ok(());\n        }\n        let rendered = crate::check_command::render_project_diagnostics(db, &errors);\n        reporter.abandon();\n        eprintln!(\"{rendered}\");\n        anyhow::bail!(\"{bail_context}\");\n    }\n\n    /// Compile `db` to bytecode and build a `BexEngine`.\n    fn compile_to_engine(\n        &self,\n        db: &ProjectDatabase,\n        package: SourceRoot,\n        argv: Vec<String>,\n    ) -> Result<BexEngine> {\n        let bytecode = baml_compiler2_emit::generate_project_bytecode(db, package)\n            .map_err(|e| anyhow!(\"compilation failed: {e:?}\"))?;\n        BexEngine::new_with_runtime_compiler(\n            bytecode,\n            Arc::new(sys_native::SysOps::native()),\n            argv,\n            bex_project::runtime_compiler(),\n        )\n        .map_err(|e| anyhow!(\"failed to create engine: {e:?}\"))\n    }\n\n    pub fn run(&self) -> Result<crate::ExitCode> {\n        let reporter = Reporter::new();\n        let outcome = self.run_with_reporter(&reporter);\n        emit_profiling_status();\n        outcome\n    }\n}\n\n/// A profiling failure never breaks the run, so by default it is invisible;","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/run_command.rs#L341-L377","documentation":"`generate_project_bytecode` failed while compiling the project to bytecode for the Bex engine; the error is wrapped with a debug-formatted cause. This means the project passed loading but could not be emitted to executable bytecode.","triggerScenarios":"`compile_to_engine` calls `baml_compiler2_emit::generate_project_bytecode(db, package)` and it returns an Err — e.g. unsupported language features or internal emit failures — when invoked from `load_and_compile_standalone` or `run_expression`.","commonSituations":"Compiler bugs or unhandled constructs in `.baml` sources; projects that pass diagnostics but fail a later emit phase; version skew between CLI and compiler crates.","solutions":["Inspect the debug-formatted cause `{e:?}` for the concrete emit error","Simplify or fix the offending `.baml` constructs flagged in the cause","Update the BAML CLI/compiler to the latest version","File an issue if the construct should compile"],"exampleFix":"// before\nbaml run --expr 'invalid construct'\n// after\n# fix the .baml source / expression, then retry\nbaml run --expr 'MyFunction(\"input\")'","handlingStrategy":"try-catch","validationCode":"const diags = await baml.check(dir);\nif (diags.some(d => d.severity === 'error')) throw new Error('fix diagnostics before compiling');","typeGuard":null,"tryCatchPattern":"try { const engine = await runner.loadAndCompileStandalone(); } catch (e) { if (String(e).startsWith('compilation failed:')) { console.error(e.message); process.exit(1); } throw e; }","preventionTips":["Keep the BAML CLI and compiler crates on matching versions","Avoid unsupported/experimental .baml constructs","Pin CLI versions in CI and update deliberately"],"tags":["cli","compiler","bytecode","baml"],"backgroundTag":"compilation-failed","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"}