BoundaryML/baml · error
{ctx}
Error message
{ctx} What it means
bail_on_error_diagnostics is the shared path for reporting compile-time diagnostics: it renders the project's error diagnostics via check_command::render_project_diagnostics, prints them to stderr after abandoning the reporter, then bails with the supplied `ctx` context string (e.g. "cannot pack: compilation errors found"). The actual error details live in the rendered diagnostics printed above the bail, not in the bail message itself.
Source
Thrown at baml_language/crates/baml_cli/src/pack_command.rs:524
db: &ProjectDatabase,
diagnostics: &[baml_db::baml_compiler_diagnostics::Diagnostic],
ctx: &str,
reporter: &Reporter,
) -> Result<()> {
let errors: Vec<_> = diagnostics
.iter()
.filter(|d| d.severity == Severity::Error)
.collect();
if errors.is_empty() {
return Ok(());
}
let rendered = crate::check_command::render_project_diagnostics(
db,
&errors.iter().copied().cloned().collect::<Vec<_>>(),
);
reporter.abandon();
eprintln!("{rendered}");
anyhow::bail!("{ctx}");
}
/// Return the qualified name the engine prefers when both `foo` and
/// `user.foo` resolve to the same function.
/// Suggest user functions whose name is similar to `query`. Ranked by
/// substring containment first, then jaro-winkler similarity. Returns up
/// to 5 display names, sorted.
fn function_suggestions(engine: &BexEngine, query: &str) -> Vec<String> {
let mut hits: Vec<String> = engine
.user_functions()
.into_iter()
.map(|f| f.display_name)
.filter(|name| {
name.contains(query)
|| query.contains(name.as_str())
|| strsim::jaro_winkler(name, query) > 0.7
})
.collect();View on GitHub (pinned to bd85ce9dee)
Solutions
- Read the rendered diagnostics printed above the bail message and fix each reported error in the `.baml` source.
- Run `baml check` first for a fast feedback loop, then re-run `baml pack` once clean.
- If errors come from generated/checked-in code, regenerate or restore it before packing.
Example fix
// before (broken.baml has a type error) baml pack --file broken.baml // after baml check --file broken.baml // fix reported diagnostics, then: baml pack --file broken.baml
Defensive patterns
Strategy: try-catch
Validate before calling
# pre-flight: only pack when check is clean
baml check || { echo "fix compile errors before packing" >&2; exit 2; } Try / catch
// capture stderr: diagnostics print above the bail message
let out = Command::new("baml")
.args(["pack", "-f", func])
.stderr(Stdio::piped())
.output()?;
if !out.status.success() {
eprintln!("pack failed:\n{}", String::from_utf8_lossy(&out.stderr));
} Prevention
- Make `baml check` a mandatory pre-commit/pre-pack step in CI.
- Fix diagnostics as they appear instead of batching edits.
- Keep generated BAML code in sync with its sources before packing.
When it happens
Trigger: Running `baml pack` (project or standalone mode) when the BAML sources contain compile errors — check_diagnostics or load_and_compile_project detects error-level diagnostics and calls bail_on_error_diagnostics.
Common situations: Syntax errors, type errors, or invalid expressions in `.baml` files; partially edited sources; referencing undefined functions/types; generated code drift after schema changes.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- positional `<TARGET>` and `-f/--function` are mutually exclu
- no target specified. Pass a positional `<TARGET>` to pack on
- compilation failed: {e:?}
- no `.baml` files found in {}
- two targets share subcommand name `{}` (`{}` and `{}`). Subc
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/440da1ecc62b9917.
Report an issue: GitHub.