{"record":{"id":"cdecf1bf2fa7ba18","repo":"kataras/iris","slug":"simpledate-unknown-type-of-t","errorCode":null,"errorMessage":"SimpleDate: unknown type of: %T","messagePattern":"SimpleDate: unknown type of: %T","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/jsonx/simple_date.go","lineNumber":174,"sourceCode":"// Scan completes the pg and native sql driver.Scanner interface\n// reading functionality of a custom type.\nfunc (t *SimpleDate) Scan(src any) error {\n\tswitch v := src.(type) {\n\tcase time.Time: // type was set to timestamp\n\t\tif v.IsZero() {\n\t\t\treturn nil // don't set zero, ignore it.\n\t\t}\n\t\t*t = SimpleDate(v)\n\tcase string:\n\t\ttt, err := ParseSimpleDate(v)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\t*t = tt\n\tcase nil:\n\t\t*t = SimpleDate(time.Time{})\n\tdefault:\n\t\treturn fmt.Errorf(\"SimpleDate: unknown type of: %T\", v)\n\t}\n\n\treturn nil\n}\n\n// Slice of SimpleDate.\ntype SimpleDates []SimpleDate\n\n// First returns the first element of the date slice.\nfunc (t SimpleDates) First() SimpleDate {\n\tif len(t) == 0 {\n\t\treturn SimpleDate{}\n\t}\n\n\treturn t[0]\n}\n\n// Last returns the last element of the date slice.","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/jsonx/simple_date.go#L156-L192","documentation":"SimpleDate.Scan handles src of type time.Time, string, and nil only. Any other driver value (e.g. []byte from a driver that returns text as bytes) falls into the default case and errors with \"SimpleDate: unknown type of: %T\" naming the actual Go type.","triggerScenarios":"rows.Scan into *jsonx.SimpleDate where the driver returns []byte, int64, or float64 — e.g. a TEXT/DATE column under a driver configured with binary off, or a mismatched numeric column.","commonSituations":"Postgres DATE columns through drivers returning []byte; scanning an int epoch into SimpleDate; ORM-generated scans binding the wrong column order.","solutions":["Change the column to DATE/TIMESTAMP so the driver yields time.Time.","If the type in the message is []byte, scan into *string first then call jsonx.ParseSimpleDate.","Convert ints/epoch to time.Time before scanning."],"exampleFix":"// before\nvar sd jsonx.SimpleDate\nrows.Scan(&sd) // src is []byte -> error\n// after\nvar raw string\nrows.Scan(&raw)\nsd, _ = jsonx.ParseSimpleDate(raw)","handlingStrategy":"type-guard","validationCode":"func canScanSimpleDate(src any) bool {\n\tswitch src.(type) {\n\tcase nil, time.Time, string:\n\t\treturn true\n\t}\n\treturn false\n}","typeGuard":"func knownSimpleDateSrc(src any) bool {\n\tswitch src.(type) {\n\tcase time.Time, string, nil:\n\t\treturn true\n\tdefault:\n\t\treturn false\n\t}\n}","tryCatchPattern":"var sd jsonx.SimpleDate\nif err := rows.Scan(&sd); err != nil {\n\tif strings.HasPrefix(err.Error(), \"SimpleDate: unknown type of:\") {\n\t\tvar raw string\n\t\tif e2 := rows.Scan(&raw); e2 == nil {\n\t\t\tsd, err = jsonx.ParseSimpleDate(raw)\n\t\t}\n\t}\n\treturn err\n}","preventionTips":["Use DATE/TIMESTAMP columns for SimpleDate fields","Beware drivers returning []byte; scan to string and parse manually","Add driver integration tests covering Scan types"],"tags":["go","json","scan","type-mismatch","postgres"],"backgroundTag":"unsupported-scan-type","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}