{"record":{"id":"4be96329a075228d","repo":"BoundaryML/baml","slug":"function-panicked-s","errorCode":null,"errorMessage":"Function panicked: {s}","messagePattern":"Function panicked: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"engine/language_client_cffi/src/ffi/functions.rs","lineNumber":214,"sourceCode":"                allow_stream_types,\n                &ctx,\n                type_builder.as_ref(),\n                client_registry.as_ref(),\n                env_vars,\n            )\n        })) {\n            Ok(future) => future.await,\n            Err(panic_info) => {\n                // Handle the panic case - create an error result\n                let error_msg = if let Some(s) = panic_info.downcast_ref::<&str>() {\n                    format!(\"Function panicked: {s}\")\n                } else if let Some(s) = panic_info.downcast_ref::<String>() {\n                    format!(\"Function panicked: {s}\")\n                } else {\n                    \"Function panicked with unknown error\".to_string()\n                };\n\n                Err(anyhow::anyhow!(error_msg))\n            }\n        };\n\n        match result {\n            Ok(result) => send_result_to_callback(id, !allow_stream_types, &result, runtime),\n            Err(e) => {\n                send_error_to_callback(id, &e);\n            }\n        };\n    });\n\n    Ok(())\n}\n\n/// Extern \"C\" function that returns immediately, scheduling the async call.\n/// Once the asynchronous function completes, the provided callback is invoked.\n/// Returns Buffer with InvocationResponse (empty on success, error message on failure).\n/// Caller must free with free_buffer().","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/ffi/functions.rs#L196-L232","documentation":"When the async task running call_function_parse_from_c_inner panics, the panic is caught by the catch_unwind-style handler and re-reported as this error to the caller's callback. The message embeds the panic payload string, surfacing an internal Rust crash as a normal error instead of aborting the process.","triggerScenarios":"Any internal panic during parse execution — downcast failures, assertion failures, index-out-of-bounds in runtime code, or unwrap() on unexpected runtime state while parsing text.","commonSituations":"Buggy or mismatched native library versions, pathological input text triggering runtime edge cases, or incompatibilities between the compiled runtime and loaded BAML files.","solutions":["Read the embedded panic payload in the message to identify the panicking operation","Upgrade to the latest BAML version — internal panics are usually fixed upstream","File a bug report with the panic message, input text shape, and library versions if it persists","Catch the error at the callback and fall back to re-running without the parse path"],"exampleFix":"// before (ignoring error detail)\ncatch (e) { log(e) }\n// after\ncatch (e) {\n  if (String(e).includes(\"Function panicked\")) {\n    log(\"BAML internal panic, report with versions\", e);\n    result = fallbackParse(rawText);\n  }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = await parse_callback_result()\nexcept Exception as e:\n    if 'Function panicked' in str(e):\n        log.error('BAML internal panic', exc=e)\n        result = fallback_parse(raw_text)\n    else:\n        raise","preventionTips":["Keep BAML client and native library on the same latest version","Report recurring panics upstream with the panic payload and versions","Validate input text shapes before sending to parse","Wrap parse calls with a non-parse fallback path"],"tags":["rust","panic","internal-error","ffi"],"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"}