{"record":{"id":"452ff68fb59a9187","repo":"BoundaryML/baml","slug":"compilation-failed-e-test-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/test_command.rs","lineNumber":387,"sourceCode":"            if !errors.is_empty() {\n                // Render the full diagnostic block so test errors look like\n                // run/pack errors instead of a bullet list of messages. Sources\n                // and paths cover every user file plus builtins — an error in one\n                // file may carry related spans elsewhere.\n                let rendered = crate::check_command::render_project_diagnostics(db, &errors);\n                reporter.abandon();\n                eprintln!(\"{rendered}\");\n                return Ok(crate::ExitCode::Other);\n            }\n\n            // 3. Compile + engine + runtime\n            let compiled = crate::bytecode_cache::compile_program_artifacts(\n                db,\n                package,\n                cache.as_ref(),\n                reuse_plan.as_ref(),\n            )\n            .map_err(|e| anyhow!(\"compilation failed: {e:?}\"))?;\n            if let Some(ctx) = cache {\n                let fresh = fresh_diagnostics\n                    .as_ref()\n                    .expect(\"a cache is present, so fresh diagnostics were computed\");\n                ctx.verify_and_store(\n                    &session,\n                    &compiled,\n                    fresh,\n                    reuse_plan.as_ref(),\n                    stdlib_interface_hit,\n                )?;\n            }\n            // Warm-run evidence: with the stdlib interface seeded this is 0 (the\n            // seed served every stdlib package); a cold run reports up to 6.\n            crate::bytecode_cache::cache_debug(format_args!(\n                \"stdlib interface: {} honest derivation(s) this process\",\n                baml_db::baml_compiler2_hir_ty::package_interface::stdlib_honest_derivations()\n            ));","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/test_command.rs#L369-L405","documentation":"During `baml test`, the CLI compiled the project's program artifacts (via `compile_program_artifacts`, with optional bytecode cache and reuse plan) and the compiler returned an error. The CLI wraps it with `anyhow!(\"compilation failed: {e:?}\")`, including the debug-formatted underlying compiler error, and aborts the test run — no tests execute until the project compiles.","triggerScenarios":"Any diagnostic error in the BAML sources under test (syntax error, type error, unresolved reference, invalid manifest/config) that makes `compile_program_artifacts` fail during `TestArgs::run`.","commonSituations":"A recent edit introduced a syntax or type error; a partially-merged refactor left broken sources; an incompatible baml.toml; running tests on a branch that doesn't compile; stale generated code referenced by sources.","solutions":["Read the debug payload after \"compilation failed:\" — it names the file/span and the underlying compiler diagnostic; fix that error first.","Run the compile/check step alone (e.g. `baml run --list` or an equivalent check command) to surface diagnostics faster.","Revert or complete the recent edit that broke compilation.","Regenerate any generated BAML sources and verify baml.toml is valid for this toolchain version."],"exampleFix":"// before (my_func.baml)\nfunction Foo() -> string { clients FooClient } // unresolved client\n// after\nfunction Foo() -> string { clients Gpt4 } // existing client","handlingStrategy":"validation","validationCode":"// shell: fail fast before tests if sources don't compile\nbaml run --list > /dev/null 2> compile_err.log || { cat compile_err.log; exit 1; }","typeGuard":null,"tryCatchPattern":"if ! baml test 2>err.log; then\n  grep -q 'compilation failed' err.log && { echo \"fix compiler errors first\"; cat err.log; }\n  exit 1\nfi","preventionTips":["Run a quick compile/check step in pre-commit hooks and CI before tests.","Keep baml.toml and generated sources valid for your toolchain version.","Fix compiler diagnostics at the named file/span before rerunning tests."],"tags":["cli","compilation","testing","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-14T05:17:10.506Z"}