{"record":{"id":"3aa089e41f4a3348","repo":"BoundaryML/baml","slug":"s-exports","errorCode":null,"errorMessage":"%s","messagePattern":"%s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/baml_go/exports.go","lineNumber":94,"sourceCode":"func decodeAsyncResponse(buf C.Buffer) error {\n\tdefer C.WrapFreeBuffer(buf)\n\n\t// Empty buffer means success (task was spawned)\n\tif buf.ptr == nil || buf.len == 0 {\n\t\treturn nil\n\t}\n\n\tcontent_bytes := C.GoBytes(unsafe.Pointer(buf.ptr), C.int32_t(buf.len))\n\n\tvar response cffi.InvocationResponse\n\tif err := proto.Unmarshal(content_bytes, &response); err != nil {\n\t\treturn fmt.Errorf(\"failed to unmarshal FFI response: %w\", err)\n\t}\n\n\t// Check if response contains an error\n\tswitch response.GetResponse().(type) {\n\tcase *cffi.InvocationResponse_Error:\n\t\treturn fmt.Errorf(\"%s\", response.GetError())\n\tdefault:\n\t\t// Success or nil response means success\n\t\treturn nil\n\t}\n}\n\nfunc CallFunctionFromC(runtime unsafe.Pointer, functionName string, encodedArgs []byte, id uint32) error {\n\tcFunctionName := C.CString(functionName)\n\tdefer C.free(unsafe.Pointer(cFunctionName))\n\n\tcEncodedArgs := (*C.char)(unsafe.Pointer(&encodedArgs[0]))\n\n\tresult := C.WrapCallFunctionFromC(runtime, cFunctionName, cEncodedArgs, C.uintptr_t(len(encodedArgs)), C.uint32_t(id))\n\n\treturn decodeAsyncResponse(result)\n}\n\nfunc CallFunctionStreamFromC(runtime unsafe.Pointer, functionName string, encodedArgs []byte, id uint32) error {","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/exports.go#L76-L112","documentation":"After successfully unmarshaling the FFI response, decodeAsyncResponse checks whether the InvocationResponse holds an Error oneof; if so, it surfaces the native BAML runtime's error message verbatim via fmt.Errorf(\"%s\", ...). This is the pass-through channel for errors that occurred inside the BAML runtime (compile errors, missing functions, LLM provider failures).","triggerScenarios":"Calling a BAML function (CallFunctionFromC / stream / parse / BuildRequestFromC / CancelFunctionCall) whose native execution returned InvocationResponse_Error — e.g. unknown function name, baml_src compile error, or provider/API failure inside the runtime.","commonSituations":"Calling a function name that doesn't exist in baml_src; a syntax error in a .baml file; expired or invalid LLM API key passed via env vars; malformed arguments that fail runtime type checking.","solutions":["Read the wrapped %s message — it is the native runtime's own diagnostic (e.g. 'function X not found' or 'failed to parse') and fix the named cause","Validate the function name exists in your baml_src directory and matches the generated client","Run `baml-cli dev` or `baml-cli test` locally to catch compile errors in .baml files before runtime","Verify provider credentials (OPENAI_API_KEY etc.) are present in the env vars passed at runtime creation"],"exampleFix":"// before\nresult, err := baml.CallFunction(ctx, \"ExtractReusme\", params) // typo'd function\n// after\nresult, err := baml.CallFunction(ctx, \"ExtractResume\", params) // matches fn ExtractResume in baml_src","handlingStrategy":"try-catch","validationCode":"if !baml.FunctionExists(ctx, \"ExtractResume\") {\n    return fmt.Errorf(\"function ExtractResume not defined in baml_src\")\n}","typeGuard":null,"tryCatchPattern":"result, err := baml.CallFunction(ctx, fnName, args)\nvar rtErr *baml.RuntimeError\nif errors.As(err, &rtErr) {\n    log.Errorf(\"baml runtime error: %s\", rtErr.Error()) // native message\n}","preventionTips":["Run `baml-cli dev`/tests to catch .baml compile errors before deploying","Validate function names against your baml_src definitions","Verify provider API keys are set in the env vars passed at runtime creation"],"tags":["ffi","runtime-error","error-passthrough"],"backgroundTag":"api-error-response","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"}