{"record":{"id":"440da1ecc62b9917","repo":"BoundaryML/baml","slug":"ctx","errorCode":null,"errorMessage":"{ctx}","messagePattern":"\\{ctx\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/pack_command.rs","lineNumber":524,"sourceCode":"    db: &ProjectDatabase,\n    diagnostics: &[baml_db::baml_compiler_diagnostics::Diagnostic],\n    ctx: &str,\n    reporter: &Reporter,\n) -> Result<()> {\n    let errors: Vec<_> = diagnostics\n        .iter()\n        .filter(|d| d.severity == Severity::Error)\n        .collect();\n    if errors.is_empty() {\n        return Ok(());\n    }\n    let rendered = crate::check_command::render_project_diagnostics(\n        db,\n        &errors.iter().copied().cloned().collect::<Vec<_>>(),\n    );\n    reporter.abandon();\n    eprintln!(\"{rendered}\");\n    anyhow::bail!(\"{ctx}\");\n}\n\n/// Return the qualified name the engine prefers when both `foo` and\n/// `user.foo` resolve to the same function.\n/// Suggest user functions whose name is similar to `query`. Ranked by\n/// substring containment first, then jaro-winkler similarity. Returns up\n/// to 5 display names, sorted.\nfn function_suggestions(engine: &BexEngine, query: &str) -> Vec<String> {\n    let mut hits: Vec<String> = engine\n        .user_functions()\n        .into_iter()\n        .map(|f| f.display_name)\n        .filter(|name| {\n            name.contains(query)\n                || query.contains(name.as_str())\n                || strsim::jaro_winkler(name, query) > 0.7\n        })\n        .collect();","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/pack_command.rs#L506-L542","documentation":"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.","triggerScenarios":"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.","commonSituations":"Syntax errors, type errors, or invalid expressions in `.baml` files; partially edited sources; referencing undefined functions/types; generated code drift after schema changes.","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."],"exampleFix":"// before (broken.baml has a type error)\nbaml pack --file broken.baml\n\n// after\nbaml check --file broken.baml\n// fix reported diagnostics, then:\nbaml pack --file broken.baml","handlingStrategy":"try-catch","validationCode":"# pre-flight: only pack when check is clean\nbaml check || { echo \"fix compile errors before packing\" >&2; exit 2; }","typeGuard":null,"tryCatchPattern":"// capture stderr: diagnostics print above the bail message\nlet out = Command::new(\"baml\")\n    .args([\"pack\", \"-f\", func])\n    .stderr(Stdio::piped())\n    .output()?;\nif !out.status.success() {\n    eprintln!(\"pack failed:\\n{}\", String::from_utf8_lossy(&out.stderr));\n}","preventionTips":["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."],"tags":["cli","compile-diagnostics","baml-pack"],"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"}