{"record":{"id":"78c03c16e17f7bad","repo":"BoundaryML/baml","slug":"decodecheckedvalue-valuechecked-is-nil","errorCode":null,"errorMessage":"decodeCheckedValue: valueChecked is nil","messagePattern":"decodeCheckedValue: valueChecked is nil","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"engine/language_client_go/baml_go/serde/decode.go","lineNumber":292,"sourceCode":"\t\t\tdebugLog(\" -> got a nil goType, so returning nil\\n\")\n\t\t\t// got a nill value, so return nil\n\t\t\tgoType := convertFieldTypeToGoType(valueUnion.SelfType, typeMap)\n\t\t\t// goType should be a pointer\n\t\t\tptr := reflect.New(goType)\n\t\t\t// use .Elem to return the inner pointer\n\t\t\treturn ptr.Elem(), goType\n\t\t}\n\t\tptr := reflect.New(goType)\n\t\tptr.Elem().Set(value)\n\t\treturn ptr, ptr.Type()\n\t}\n\n\treturn value, goType\n}\n\nfunc decodeCheckedValue(valueChecked *cffi.CFFIValueChecked, typeMap TypeMap) (reflect.Value, reflect.Type) {\n\tif valueChecked == nil {\n\t\tpanic(\"decodeCheckedValue: valueChecked is nil\")\n\t}\n\n\tvalue := valueChecked.Value\n\tdecodedValue, _ := Decode(value, typeMap)\n\tchecks := make(map[string]shared.Check, len(valueChecked.Checks))\n\tfor _, check := range valueChecked.Checks {\n\t\tchecks[string(check.Name)] = shared.Check{\n\t\t\tName:       string(check.Name),\n\t\t\tExpression: string(check.Expression),\n\t\t\tStatus:     string(check.Status),\n\t\t}\n\t}\n\tgoType, ok := typeMap.GetType(valueChecked.Name)\n\tif !ok {\n\t\tpanic(\"error decoding value, checked type not found: \" + valueChecked.Name.String())\n\t}\n\tcheckedValue := reflect.New(goType)\n\tcheckedValue.Elem().FieldByName(\"Value\").Set(decodedValue)","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/baml_go/serde/decode.go#L274-L310","documentation":"decodeCheckedValue panics when the *cffi.CFFIValueChecked is nil. A checked value (a value with assertion/check results) must carry a non-nil pointer so the decoder can read its value and checks; nil indicates malformed FFI data from the runtime.","triggerScenarios":"Decode() encountering a CFFIValue whose variant is a checked value with a nil CFFIValueChecked pointer.","commonSituations":"Version skew between generated client and native runtime, native-side bug producing empty checked values, or corrupted streaming responses.","solutions":["Regenerate baml_client and ensure the baml runtime version matches the Go bindings","Guard call sites: skip/short-circuit decoding when the checked value is nil","Wrap Decode in a recover() if processing untrusted/malformed responses","Report the triggering payload to BAML maintainers"],"exampleFix":"// before\nv, t := serde.Decode(cv, typeMap)\n// after\nif cv == nil || cv.ValueChecked == nil {\n  return reflect.Value{}, nil\n}\nv, t := serde.Decode(cv, typeMap)","handlingStrategy":"type-guard","validationCode":"if checked == nil { return reflect.Value{}, nil }","typeGuard":"func hasChecked(v *cffi.CFFIValue) bool { return v != nil && v.GetValueChecked() != nil }","tryCatchPattern":"defer func() { if r := recover(); r != nil { log.Printf(\"checked-value decode panic: %v\", r) } }()\nv, _ := serde.Decode(cv, typeMap)","preventionTips":["Verify non-nil CFFIValueChecked before decoding checks/asserts","Keep generated client and runtime versions aligned","Wrap streaming decodes in recover() since payloads can be partial"],"tags":["go","panic","decoding","null"],"backgroundTag":"null-argument","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}