{"record":{"id":"e72e3f78fd56fca7","repo":"BoundaryML/baml","slug":"bamlerror-err","errorCode":null,"errorMessage":"BamlError: {err:?}","messagePattern":"BamlError: (.+?)","errorType":"exception","errorClass":"napi::Error","httpStatus":null,"severity":"error","filePath":"engine/language_client_typescript/src/errors.rs","lineNumber":134,"sourceCode":"                }\n            },\n            LLMResponse::UserFailure(msg) => napi::Error::new(\n                napi::Status::GenericFailure,\n                format!(\"BamlError: BamlInvalidArgumentError: {msg}\"),\n            ),\n            LLMResponse::InternalFailure(_) => napi::Error::new(\n                napi::Status::GenericFailure,\n                format!(\n                    \"BamlError: BamlClientError: Something went wrong with the LLM client: {err}\"\n                ),\n            ),\n            LLMResponse::Cancelled(msg) => napi::Error::new(\n                napi::Status::GenericFailure,\n                format!(\"BamlAbortError: Operation was aborted: {msg}\"),\n            ),\n        }\n    } else {\n        napi::Error::new(napi::Status::GenericFailure, format!(\"BamlError: {err:?}\"))\n    }\n}\n\nfn throw_baml_validation_error(\n    prompt: &str,\n    raw_output: &str,\n    message: &str,\n    detailed_message: Option<&str>,\n) -> napi::Error {\n    let error_json = serde_json::json!({\n        \"type\": \"BamlValidationError\",\n        \"prompt\": prompt,\n        \"raw_output\": raw_output,\n        \"message\": format!(\"BamlValidationError: {}\", message),\n        \"detailed_message\": detailed_message,\n    });\n    napi::Error::new(napi::Status::GenericFailure, error_json.to_string())\n}","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_typescript/src/errors.rs#L116-L152","documentation":"This is the fallback branch of from_anyhow_error: when the error chain cannot be classified into an LLM response variant, BAML formats the raw anyhow error with {err:?} under a generic BamlError prefix. It means an unstructured internal error escaped the typed error plumbing.","triggerScenarios":"Any unclassified anyhow error bubbling out of the runtime into the NAPI boundary — runtime startup failures, internal panics converted to errors, misconfigured context, or bugs in error classification.","commonSituations":"Running with an incompatible runtime context manager, corrupt BAML config loaded at runtime, or internal invariant violations that never reached the LLM.","solutions":["Read the Debug-formatted {err:?} payload for the root cause","Check baml_src configuration and that the runtime context is initialized correctly","Reproduce with BAML_DEBUG/verbose logging enabled to capture the full error chain","File a bug with the full error if it persists — this branch indicates an unclassified error"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// sanity-check runtime context is initialized\nif (!ctxManager || typeof ctxManager.getContext !== 'function') throw new Error('BAML runtime context not initialized');","typeGuard":"const isGenericBamlError = (e: unknown): boolean => typeof e === 'string' && e.startsWith('BamlError:') && !e.includes('BamlClientError');","tryCatchPattern":"try {\n  const result = await b.MyFunction(args);\n} catch (e) {\n  const msg = typeof e === 'string' ? e : String(e);\n  if (msg.startsWith('BamlError:')) {\n    console.error('Unclassified BAML error:', msg);\n    throw new Error('BAML internal failure: ' + msg);\n  }\n  throw e;\n}","preventionTips":["Keep baml_src and runtime versions in sync","Enable verbose logging to capture full error chains","Report persistent generic BamlErrors upstream — they indicate classification gaps","Validate context/env setup before starting calls"],"tags":["internal","unclassified","napi","typescript"],"backgroundTag":"internal-invariant-violation","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"}