{"record":{"id":"0bf8dea4a152e645","repo":"redis/go-redis","slug":"cannot-scan-redis-result-s-into-struct-field-s","errorCode":null,"errorMessage":"cannot scan redis.result %s into struct field %s.%s of type %s, error-%s","messagePattern":"cannot scan redis\\.result (.+?) into struct field (.+?)\\.(.+?) of type (.+?), error-(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hscan/structmap.go","lineNumber":123,"sourceCode":"\n\tif isPtr && v.Type().NumMethod() > 0 && v.CanInterface() {\n\t\tswitch scan := v.Interface().(type) {\n\t\tcase Scanner:\n\t\t\treturn scan.ScanRedis(value)\n\t\tcase encoding.TextUnmarshaler:\n\t\t\treturn scan.UnmarshalText(util.StringToBytes(value))\n\t\tcase encoding.BinaryUnmarshaler:\n\t\t\treturn scan.UnmarshalBinary(util.StringToBytes(value))\n\t\t}\n\t}\n\n\tif isPtr {\n\t\tv = v.Elem()\n\t}\n\n\tif err := field.fn(v, value); err != nil {\n\t\tt := s.value.Type()\n\t\treturn fmt.Errorf(\"cannot scan redis.result %s into struct field %s.%s of type %s, error-%s\",\n\t\t\tvalue, t.Name(), t.Field(field.index).Name, t.Field(field.index).Type, err.Error())\n\t}\n\treturn nil\n}\n","sourceCodeStart":105,"sourceCodeEnd":128,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/internal/hscan/structmap.go#L105-L128","documentation":"When a per-field decoder fails while scanning a Redis hash result into a struct field (e.g. 'strconv.ParseInt: parsing \"abc\"' for an int field), hscan wraps the failure with full context: the raw value, the struct name, the field name, the field type, and the underlying error. It points at a type mismatch between the stored Redis string and the declared Go field type.","triggerScenarios":"HGETALL returns a non-numeric or out-of-range string for an int/float/bool field; a negative value scanned into a uint field; empty string decoded into a number.","commonSituations":"Data written by another app in a different format; schema drift where a field changed type; Redis values like 'nil' or '' stored where numbers are expected.","solutions":["Read the embedded error-%s suffix to see the exact parse failure","Fix the struct field type to match the stored data (e.g. int64 for large numbers)","Clean/normalize the stored data or handle sentinel values before scanning","Use a string field and parse manually when values may be non-numeric"],"exampleFix":"// before\ntype User struct {\n\tAge uint `redis:\"age\"` // stored: \"-5\"\n}\n// after\ntype User struct {\n\tAge int64 `redis:\"age\"`\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := redis.Scan(&user); err != nil {\n\tvar scanErr string = err.Error()\n\tif strings.HasPrefix(scanErr, \"cannot scan redis.result\") {\n\t\t// parse field name and underlying cause from the message\n\t\tlog.Printf(\"schema/data mismatch: %s\", scanErr)\n\t}\n\treturn err\n}","preventionTips":["Match Go field types to the actual stored Redis values","Widen numeric fields (int64) to avoid range errors","Guard nullable/empty stored values with string fields and manual parsing","Add integration tests scanning real production-shaped data"],"tags":["struct-scan","type-mismatch","deserialization"],"backgroundTag":"scan-type-mismatch","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}