{"record":{"id":"5c91301923cdc73d","repo":"BoundaryML/baml","slug":"compilation-failed-e","errorCode":null,"errorMessage":"compilation failed: {e:?}","messagePattern":"compilation failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/generate.rs","lineNumber":350,"sourceCode":"                eprintln!(\"add a generator section to `baml.toml`, for example:\");\n                eprintln!();\n                eprintln!(\"  [generator.my_client]\");\n                eprintln!(\"  output_type = \\\"python/pydantic\\\"\");\n                eprintln!(\"  output_dir = \\\"../python\\\"\");\n                eprintln!(\"  naming_convention = \\\"preserve-case\\\"\");\n            }\n            return Ok(crate::ExitCode::Other);\n        }\n\n        let embedded_baml_toml = build_embedded_baml_toml(&from)?;\n\n        // Build the codegen SymbolPool from the compiler database.\n        let pool = baml_ide::build_symbol_pool(&db);\n\n        reporter.spin(\"Compiling\", format!(\"{} file(s)\", source_files.len()));\n        let program = db\n            .get_bytecode(package)\n            .map_err(|e| anyhow!(\"compilation failed: {e:?}\"))?;\n        let baml_bytecode = baml_artifact::encode(baml_artifact::ArtifactKind::Program, &program)\n            .map_err(|e| anyhow!(\"failed to serialize BAML bytecode: {e}\"))?;\n        let source_root = from.join(\"baml_src\");\n        let user_baml_files = source_files\n            .iter()\n            .map(|source_file| {\n                let path = source_file.path(&db);\n                let relative_path = path\n                    .strip_prefix(&source_root)\n                    .or_else(|_| path.strip_prefix(&from))\n                    .with_context(|| {\n                        format!(\n                            \"BAML source {} is outside project root {}\",\n                            path.display(),\n                            from.display()\n                        )\n                    })?;\n                Ok((","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/generate.rs#L332-L368","documentation":"During `baml generate`, after building the compiler database and symbol pool, the CLI fetches the compiled program bytecode via `db.get_bytecode(package)`. If the compiler produces any diagnostics/errors, they are formatted with `{e:?}` and wrapped in this \"compilation failed\" anyhow error.","triggerScenarios":"`baml generate` on a project whose baml_src contains BAML source that does not compile — syntax errors, type errors, unresolved functions/clients, invalid generator config in baml.toml.","commonSituations":"A recent edit to a .baml file introduced an error; a generator block references a missing client; baml.toml and baml_src are out of sync; using new language features with an older CLI.","solutions":["Read the detailed diagnostics after 'compilation failed:' and fix the reported BAML errors.","Run `baml-cli fmt` / open the file in an editor with BAML LSP to locate the offending lines.","Verify your generator block and clients in baml_src compile (e.g. via the VS Code BAML extension's diagnostics).","Update the CLI if the errors mention unsupported syntax/features (version mismatch)."],"exampleFix":"// before (baml_src/generator.baml)\ngenerator ClientGenerator { ... provider \"baml-openai\" }  // typo'd provider\n// after\ngenerator ClientGenerator { ... provider \"openai\" }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match baml_generate() {\n  Err(e) if e.to_string().starts_with(\"compilation failed\") => {\n    eprintln!(\"Fix BAML diagnostics before generating: {e:#}\");\n    std::process::exit(1);\n  }\n  Err(e) => return Err(e),\n  Ok(_) => {}\n}","preventionTips":["Run the BAML LSP/VS Code extension to catch diagnostics before generating.","Compile or fmt (baml-cli fmt) as a pre-commit gate in CI.","Keep baml.toml and baml_src changes in the same commit.","Pin the CLI version your project's BAML syntax targets."],"tags":["compilation","baml","cli"],"backgroundTag":"schema-validation-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"}