{"record":{"id":"2fe57cbb227ce945","repo":"BoundaryML/baml","slug":"unexpected-type-for-duration-t","errorCode":null,"errorMessage":"unexpected type for duration: %T","messagePattern":"unexpected type for duration: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_timing.go","lineNumber":53,"sourceCode":"\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":35,"sourceCodeEnd":58,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_timing.go#L35-L58","documentation":"When the \"duration_ms\" FFI call returns a non-nil value, DurationMs() asserts it is a Go int64 before returning a pointer to it. A non-int64, non-nil result (e.g. float64 or uint64 from the bridge decoder) triggers this error. Like the start-time variant, this is a bridge-encoding contract violation rather than caller misuse.","triggerScenarios":"Calling DurationMs() when the bridge returns a non-nil value of a type other than int64 for \"duration_ms\" (e.g. float64 after a native encoding change).","commonSituations":"Version drift between the baml Go bindings and the native runtime changing numeric encodings; patched or custom cffi decoders returning wrapped numbers.","solutions":["Inspect %T in the error message to learn the actual returned Go type.","Sync the baml Go module version with the native BAML runtime version so int64 encoding is restored.","As a workaround, access duration via JSON/other accessors and convert the alternate numeric type yourself.","Report an upstream decoding bug if versions match and the error persists."],"exampleFix":"// before (strict assertion)\ndur, err := timing.DurationMs()\nif err != nil {\n    return err\n}\nlog.Println(*dur)\n\n// after: degrade gracefully when the bridge type drifts\ndur, err := timing.DurationMs()\nif err != nil {\n    log.Printf(\"duration type mismatch: %v\", err)\n    return nil\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isInt64(v any) bool { _, ok := v.(int64); return ok }","tryCatchPattern":"dur, err := timing.DurationMs()\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected type for duration\") {\n        log.Printf(\"duration encoding drift: %v\", err)\n        return nil, nil\n    }\n    return nil, err\n}","preventionTips":["After any BAML upgrade, smoke-test timing accessors in CI.","Report the %T value upstream when versions are aligned.","Avoid custom numeric conversions in decoders that could change FFI types."],"tags":["go","ffi","type-mismatch","timing"],"backgroundTag":"type-mismatch","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"}