{"record":{"id":"83144be72970fc40","repo":"BoundaryML/baml","slug":"failed-to-get-usage-w-rawobjects-function-log","errorCode":null,"errorMessage":"failed to get usage: %w","messagePattern":"failed to get usage: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_function_log.go","lineNumber":86,"sourceCode":"\nfunc (f *functionLog) Timing() (Timing, error) {\n\tresult, err := raw_objects.CallMethod(f, \"timing\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get timing: %w\", err)\n\t}\n\n\ttiming, ok := result.(Timing)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for timing: %T\", result)\n\t}\n\n\treturn timing, nil\n}\n\nfunc (f *functionLog) Usage() (Usage, error) {\n\tresult, err := raw_objects.CallMethod(f, \"usage\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get usage: %w\", err)\n\t}\n\n\tusage, ok := result.(Usage)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for usage: %T\", result)\n\t}\n\n\treturn usage, nil\n}\n\nfunc (f *functionLog) RawLLMResponse() (string, error) {\n\tresult, err := raw_objects.CallMethod(f, \"raw_llm_response\", nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get raw LLM response: %w\", err)\n\t}\n\n\tresponse, ok := result.(string)\n\tif !ok {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_function_log.go#L68-L104","documentation":"This error wraps any failure from raw_objects.CallMethod when Usage() fetches the 'usage' attribute of a FunctionLog over the C FFI. Like the other accessors it is a wrapper: the meaningful cause (empty FFI buffer, nil pointer, protobuf unmarshal error, or object decode failure) is in the wrapped error. It means the runtime could not supply a usable usage object.","triggerScenarios":"Calling Usage() on an invalid/freed functionLog; FFI method invocation returning an empty buffer or nil pointer; proto unmarshalling or decodeObjectResponse failing for the usage response.","commonSituations":"Touching logs after the function stream finished; collector log references held too long; mismatch between generated Go client and BAML runtime versions.","solutions":["Inspect errors.Unwrap to identify the FFI failure mode.","Access usage within the stream's lifetime; don't cache log objects past request completion.","Run `baml generate` to realign client and runtime versions.","File a bug if the wrapped cause is a decode/unmarshal failure on a valid object."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if fnLog == nil {\n    return errors.New(\"function log is nil; cannot read Usage\")\n}","typeGuard":"func isCallMethodFailure(err error) bool {\n    return strings.Contains(err.Error(), \"failed to call object method\")\n}","tryCatchPattern":"usage, err := fnLog.Usage()\nif err != nil {\n    log.Printf(\"Usage unavailable: %v (wrapped: %v)\", err, errors.Unwrap(err))\n    return fmt.Errorf(\"baml usage inaccessible: %w\", err)\n}","preventionTips":["Inspect the wrapped cause via errors.Unwrap.","Read usage data within the stream's lifetime.","Regenerate the Go client after BAML upgrades.","Avoid sharing functionLog objects across goroutines/processes."],"tags":["go","ffi","wrapped-error","baml"],"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-14T05:17:10.506Z"}