{"record":{"id":"9eb86548eda7c9a0","repo":"BoundaryML/baml","slug":"message","errorCode":null,"errorMessage":"{message}","messagePattern":"\\{message\\}","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_project/src/lib.rs","lineNumber":94,"sourceCode":"impl From<IndexMap<String, BexExternalValue>> for BexArgs {\n    fn from(required: IndexMap<String, BexExternalValue>) -> Self {\n        Self {\n            required,\n            optional: IndexMap::new(),\n        }\n    }\n}\n\n/// Errors that can occur during runtime operations.\n#[derive(Debug, Error)]\npub enum RuntimeError {\n    #[error(\"{0}\")]\n    Other(String),\n\n    #[error(\"Invalid argument: {name}\")]\n    InvalidArgument { name: String },\n\n    #[error(\"{message}\")]\n    Compilation { message: String },\n\n    #[error(\"{0}\")]\n    Engine(#[from] bex_engine::EngineError),\n\n    #[error(\"Failed to convert result to owned value: {0}\")]\n    Access(#[from] bex_heap::AccessError),\n}\n\n/// True iff `err` wraps an engine cancellation panic.\n///\n/// Centralizes the cancellation-classification logic that bridges and the\n/// LSP server need to distinguish cancellation from other runtime errors.\npub fn is_cancelled_runtime_error(err: &RuntimeError) -> bool {\n    matches!(err, RuntimeError::Engine(e) if is_cancelled_engine_error(e))\n}\n\n/// Compile a BAML project from in-memory sources and initialize a runtime.","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_project/src/lib.rs#L76-L112","documentation":"RuntimeError::Compilation is raised when the BAML source fails to compile at runtime: the `message` field carries the compiler's diagnostic text. This is distinct from engine/runtime failures — it means the source itself could not be compiled into an executable form.","triggerScenarios":"Calling bex_project APIs that compile BAML source (e.g. loading/compiling a project or string of BAML) when the source contains syntax errors, unknown types/functions, or otherwise fails type/borrow checking in the compiler.","commonSituations":"Copy-pasted BAML with syntax mistakes; referencing functions/types that don't exist or were renamed; using syntax unsupported by the installed library version; dynamically generated BAML with interpolation errors.","solutions":["Read the `message` diagnostic, fix the BAML source error it points to, and recompile.","Validate the BAML file with the CLI/compiler in isolation to get precise line/column errors.","Check for renamed or removed language constructs after upgrading the baml library.","If BAML is generated at runtime, add generation-time validation to catch malformed output before compilation."],"exampleFix":"// before\nlet src = \"function Foo() { ...\"; // unbalanced brace\nproject.compile(src)?; // RuntimeError::Compilation\n// after\nlet src = \"function Foo() { \\\"ok\\\" }\";\nproject.compile(src)?;","handlingStrategy":"validation","validationCode":"// Compile-check BAML source before the runtime call\nlet diag = baml_cli::check(source_path)?; // or run `baml-cli check`\nif !diag.is_empty() {\n    eprintln!(\"fix BAML errors first: {diag:#?}\");\n    return Ok(());\n}","typeGuard":"fn is_compilation_error(err: &RuntimeError) -> Option<&str> {\n    if let RuntimeError::Compilation { message } = err { Some(message) } else { None }\n}","tryCatchPattern":"match project.compile(src) {\n    Err(RuntimeError::Compilation { message }) => {\n        eprintln!(\"BAML compilation failed:\\n{message}\");\n        // show diagnostics to the user / abort pipeline\n    }\n    other => other?,\n}","preventionTips":["Run the BAML compiler/CLI check on source before runtime compilation","Lint generated BAML at generation time","Verify referenced functions/types exist after any rename","Test BAML against the installed library version's syntax support"],"tags":["rust","compilation","baml","runtime"],"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"}