{"record":{"id":"052157313bca22d9","repo":"BoundaryML/baml","slug":"expr-function-error","errorCode":null,"errorMessage":"Expr function error: {}","messagePattern":"Expr function error: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-schema-wasm/src/runtime_wasm/mod.rs","lineNumber":817,"sourceCode":"                Ok(value)\n            }\n            _ => {\n                // Try expr function response\n                if let Some(expr_response) = &test_response.expr_function_response {\n                    log::debug!(\n                        \"[BAML parsed_response_impl] Found expr_function_response: {:?}\",\n                        expr_response.as_ref().map(|v| format!(\"{v:?}\"))\n                    );\n                    match expr_response {\n                        Ok(value) => {\n                            log::debug!(\n                                \"[BAML parsed_response_impl] Using expr function response value\"\n                            );\n                            Ok(value)\n                        }\n                        Err(e) => {\n                            log::debug!(\"[BAML parsed_response_impl] Expr function error: {e}\");\n                            Err(anyhow::anyhow!(\"Expr function error: {}\", e))\n                        }\n                    }\n                } else {\n                    log::debug!(\n                        \"[BAML parsed_response_impl] No parsed value found in either response type\"\n                    );\n                    Err(anyhow::anyhow!(\"No parsed value\"))\n                }\n            }\n        }\n        .context(\"No parsed value\")?;\n        let (flattened_checks, check_count) = serialize_value_counting_checks(parsed_response);\n        Ok(WasmParsedTestResponse {\n            value: serde_json::to_string(&flattened_checks)?,\n            check_count,\n            explanation: {\n                let j = parsed_response.explanation_json();\n                if j.is_empty() {","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-schema-wasm/src/runtime_wasm/mod.rs#L799-L835","documentation":"During WASM parsed_response_impl for a test run, the expression-function response could not be converted into a value: evaluating/serializing the expr function returned Err(e), which is re-wrapped as \"Expr function error: {e}\". This is the WASM/JS boundary reporting that the expr function's output was invalid.","triggerScenarios":"parsed_response_impl called for a test whose function is an expr function; the internal expr-function value conversion returns Err, triggering the log::debug and the anyhow error.","commonSituations":"Expr functions that throw or return unexpected shapes when invoked from the browser/WASM test runner, e.g. division by zero, wrong argument types, or a dependent client failing.","solutions":["Read the embedded {e} message for the expr function's actual failure","Run the expr function logic standalone (baml-cli) to reproduce outside WASM","Check argument types and null-handling in the expr function body","Verify the BAML sources compile and all referenced functions exist"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-validate expr function inputs on the JS side\nif (args.some((a) => a == null)) throw new Error('null argument passed to expr function');","typeGuard":"const isExprOk = (r) => r != null && r.kind === 'expr' && r.value !== undefined;","tryCatchPattern":"try {\n  const parsed = await b.test.functionUnderTest(args);\n} catch (e) {\n  if (String(e).startsWith('Expr function error:')) {\n    console.error('expr function body failed:', e.message);\n  }\n  throw e;\n}","preventionTips":["Avoid divisions/lookups that can throw inside expr functions; guard operands","Type-check expr function arguments in the BAML schema","Test expr functions standalone via baml-cli before wiring into tests"],"tags":["wasm","expr-function","testing","rust"],"backgroundTag":"unexpected-response-shape","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}