{"record":{"id":"c06ca0af889de512","repo":"BoundaryML/baml","slug":"failed-to-get-duration-w","errorCode":null,"errorMessage":"failed to get duration: %w","messagePattern":"failed to get duration: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_timing.go","lineNumber":44,"sourceCode":"\nfunc (t *timing) StartTimeUTCMs() (int64, error) {\n\tresult, err := raw_objects.CallMethod(t, \"start_time_utc_ms\", nil)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to get start time: %w\", err)\n\t}\n\n\tstartTime, ok := result.(int64)\n\tif !ok {\n\t\treturn 0, fmt.Errorf(\"unexpected type for start time: %T\", result)\n\t}\n\n\treturn startTime, nil\n}\n\nfunc (t *timing) DurationMs() (*int64, error) {\n\tresult, err := raw_objects.CallMethod(t, \"duration_ms\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get duration: %w\", err)\n\t}\n\n\tif result == nil {\n\t\treturn nil, nil\n\t}\n\n\tduration, ok := result.(int64)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for duration: %T\", result)\n\t}\n\n\treturn &duration, nil\n}\n","sourceCodeStart":26,"sourceCodeEnd":58,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_timing.go#L26-L58","documentation":"timing.DurationMs() invokes the FFI method \"duration_ms\" on the underlying timing object; any bridge error is wrapped as \"failed to get duration: %w\". Note the method deliberately returns (nil, nil) when the result is nil (duration not yet known), so this error only fires on a genuine native-side failure such as an invalid object handle or missing method.","triggerScenarios":"Calling DurationMs() on a Timing (from function logs or LLM calls, e.g. in BAML collectors) while the underlying \"duration_ms\" FFI call fails - typically a stale/invalid raw object pointer or a runtime version mismatch.","commonSituations":"Reading duration after the runtime/context was released; a call that was interrupted so timing metadata was never finalized; Go bindings not matching the installed native BAML version.","solutions":["Unwrap the error chain to find the native cause before changing your code.","Read duration within the lifetime of the FunctionLog/LLMCall and its runtime.","Align the baml Go module version with your BAML native runtime.","Treat nil duration (no error) as 'not available yet' - the API distinguishes this from failure; don't conflate the two."],"exampleFix":"// before\ndur, err := timing.DurationMs()\nif err != nil || dur == nil {\n    return errors.New(\"no duration\")\n}\n\n// after: handle nil vs error distinctly\ndur, err := timing.DurationMs()\nif err != nil {\n    return fmt.Errorf(\"duration read failed: %w\", err)\n}\nif dur == nil {\n    return nil // call still in flight; duration not finalized\n}","handlingStrategy":"try-catch","validationCode":"if timing == nil {\n    return errors.New(\"timing object is nil\")\n}","typeGuard":null,"tryCatchPattern":"dur, err := timing.DurationMs()\nswitch {\ncase err != nil:\n    return fmt.Errorf(\"duration read failed: %w\", err)\ncase dur == nil:\n    return nil // not finalized yet\n}","preventionTips":["Distinguish the (nil, nil) 'not available' case from errors; don't collapse them.","Read durations only during the object's lifetime.","Keep Go bindings and native runtime versions aligned."],"tags":["go","ffi","timing"],"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"}