{"record":{"id":"298d85cc5bd2c5bb","repo":"kataras/iris","slug":"kitchen-time-dest-is-nil","errorCode":null,"errorMessage":"kitchen time: dest is nil","messagePattern":"kitchen time: dest is nil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/jsonx/kitchen_time.go","lineNumber":54,"sourceCode":"\t\treturn KitchenTime{}, err\n\t}\n\n\treturn KitchenTime(tt), nil\n}\n\n// ParseKitchenTime reads from \"s\" and returns the KitchenTime time.\nfunc ParseKitchenTime(s string) (KitchenTime, error) {\n\tif s == \"\" || s == \"null\" {\n\t\treturn KitchenTime{}, nil\n\t}\n\n\treturn parseKitchenTime(s)\n}\n\n// UnmarshalJSON binds the json \"data\" to \"t\" with the `KitchenTimeLayout`.\nfunc (t *KitchenTime) UnmarshalJSON(data []byte) error {\n\tif t == nil {\n\t\treturn fmt.Errorf(\"kitchen time: dest is nil\")\n\t}\n\n\tif isNull(data) {\n\t\treturn nil\n\t}\n\n\tdata = trimQuotes(data)\n\n\tif len(data) == 0 {\n\t\treturn nil\n\t}\n\n\ttt, err := parseKitchenTime(string(data))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t*t = KitchenTime(tt)","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/jsonx/kitchen_time.go#L36-L72","documentation":"KitchenTime.UnmarshalJSON first checks that the receiver pointer t is non-nil before doing any decoding. If a nil *KitchenTime is passed, decoding cannot store the result anywhere, so this error is returned immediately.","triggerScenarios":"Calling json.Unmarshal(data, (*jsonx.KitchenTime)(nil)), invoking UnmarshalJSON on a nil field pointer (e.g. a *KitchenTime struct field that was never allocated), or a custom unmarshaler passing nil through.","commonSituations":"Structs with *KitchenTime fields left nil before decoding into them; reflection-based code constructing nil receivers; forgetting to initialize the target variable.","solutions":["Pass a non-nil *KitchenTime to json.Unmarshal (declare var v jsonx.KitchenTime; unmarshal into &v).","Initialize pointer struct fields before decoding: field = new(jsonx.KitchenTime).","Use a value receiver target (KitchenTime, not *KitchenTime) so &v is always non-nil."],"exampleFix":"// before\nvar t *jsonx.KitchenTime\njson.Unmarshal(data, t) // kitchen time: dest is nil\n// after\nvar t jsonx.KitchenTime\njson.Unmarshal(data, &t)","handlingStrategy":"type-guard","validationCode":"func ensureDest(t *jsonx.KitchenTime) error {\n\tif t == nil {\n\t\treturn errors.New(\"kitchen time destination must be non-nil\")\n\t}\n\treturn nil\n}","typeGuard":"func nonNilKitchenTime(t *jsonx.KitchenTime) (*jsonx.KitchenTime, bool) {\n\tif t == nil {\n\t\treturn new(jsonx.KitchenTime), false\n\t}\n\treturn t, true\n}","tryCatchPattern":"if err := json.Unmarshal(data, kt); err != nil {\n\tif strings.Contains(err.Error(), \"dest is nil\") {\n\t\treturn fmt.Errorf(\"unmarshal target was nil; allocate before decoding: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Always unmarshal into &value where value is a declared KitchenTime, never a nil pointer.","Initialize *KitchenTime struct fields with new(KitchenTime) before decoding.","Add a nil check in wrapper unmarshalers before delegating to UnmarshalJSON."],"tags":["json","unmarshal","nil-pointer","go"],"backgroundTag":"nil-unmarshal-destination","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}