{"record":{"id":"5300d35a0410b26e","repo":"BoundaryML/baml","slug":"bail-context","errorCode":null,"errorMessage":"{bail_context}","messagePattern":"\\{bail_context\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/run_command.rs","lineNumber":348,"sourceCode":"    fn render_and_bail_on_errors(\n        &self,\n        diagnostics: &[baml_db::baml_compiler_diagnostics::Diagnostic],\n        db: &ProjectDatabase,\n        bail_context: &str,\n        reporter: &Reporter,\n    ) -> Result<()> {\n        let errors: Vec<_> = diagnostics\n            .iter()\n            .filter(|d| d.severity == Severity::Error)\n            .cloned()\n            .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:?}\"))","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/run_command.rs#L330-L366","documentation":"Project diagnostics reported compilation errors, so the command aborts by rendering the diagnostics to stderr and bailing with the caller-supplied context message (`bail_context`). It is a generic wrapper: the real details are in the rendered diagnostics above the message.","triggerScenarios":"`render_and_bail_on_errors` is called by `check_project_diagnostics`, `load_and_compile`, or `run_expression` and the error list from the project database is non-empty.","commonSituations":"Syntax or type errors in `.baml` files; referencing unknown functions/classes; broken imports — surfaced during `baml check`, `baml run`, or expression evaluation.","solutions":["Read the rendered diagnostics printed above the bail message and fix the reported `.baml` errors","Run `baml check` to see the full diagnostic list","Fix type/name errors in the offending `.baml` source files"],"exampleFix":"// before\nfunction Foo(x: int32) { ... }  // unknown type int32\n// after\nfunction Foo(x: int) { ... }","handlingStrategy":"try-catch","validationCode":"const diags = await baml.check(projectDir);\nconst errors = diags.filter(d => d.severity === 'error');\nif (errors.length) { console.error(baml.renderDiagnostics(diags)); process.exit(1); }","typeGuard":null,"tryCatchPattern":"try { await baml.loadAndCompile(dir); } catch (e) { console.error(e.message); // rendered diagnostics were already on stderr\n  process.exit(1); }","preventionTips":["Run `baml check` in CI before run/generate","Fix .baml diagnostics as they appear rather than batching","Keep editor BAML LSP enabled to catch errors at write time"],"tags":["cli","compilation","diagnostics","baml"],"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"}