kataras/iris · error
simple dates: scan: invalid type of: %T
Error message
simple dates: scan: invalid type of: %T
What it means
SimpleDates.Scan scans a JSON array of dates stored in a single column (json/jsonb). It accepts only []byte or string src and then json.Unmarshals into the slice; any other driver type (int64, time.Time, float64, etc.) is rejected with "simple dates: scan: invalid type of: %T".
Source
Thrown at x/jsonx/simple_date.go:224
}
return list
}
// Scan completes the pg and native sql driver.Scanner interface.
func (t *SimpleDates) Scan(src any) error {
if src == nil {
return nil
}
var data []byte
switch v := src.(type) {
case []byte:
data = v
case string:
data = []byte(v)
default:
return fmt.Errorf("simple dates: scan: invalid type of: %T", src)
}
err := json.Unmarshal(data, t)
return err
}
// Value completes the pg and native sql driver.Valuer interface.
func (t SimpleDates) Value() (driver.Value, error) {
if len(t) == 0 {
return nil, nil
}
b, err := json.Marshal(t)
return b, err
}
// Contains reports if the "date" exists inside "t".
func (t SimpleDates) Contains(date SimpleDate) bool {View on GitHub (pinned to 7bedaf55a0)
Solutions
- Store the list as a JSON array in a json/jsonb (or TEXT) column so src is []byte/string.
- Fix struct/query so the JSON column is selected into the SimpleDates field.
- If the source is date[], scan into []time.Time and build jsonx.SimpleDates manually.
Example fix
// before: column date[] scanned into SimpleDates -> error // after: column jsonb containing ["2024-01-01","2024-01-02"] var dates jsonx.SimpleDates rows.Scan(&dates)
Defensive patterns
Strategy: type-guard
Validate before calling
func canScanSimpleDates(src any) bool {
switch src.(type) {
case []byte, string:
return true
}
return false
} Type guard
func knownSimpleDatesSrc(src any) bool {
switch src.(type) {
case []byte, string:
return true
default:
return false
}
} Try / catch
var dates jsonx.SimpleDates
if err := rows.Scan(&dates); err != nil {
if strings.HasPrefix(err.Error(), "simple dates: scan: invalid type") {
return fmt.Errorf("column must be json/text containing a JSON date array: %w", err)
}
return err
} Prevention
- Store lists of dates as json/jsonb or TEXT columns
- Do not bind SQL ARRAY or scalar columns to SimpleDates
- Verify Value()/Scan() round-trip in tests
When it happens
Trigger: Scanning a non-text/non-json column (e.g. TIMESTAMP, BIGINT, or an ARRAY type the driver decodes to something else) into *jsonx.SimpleDates; the column decode yields time.Time or int64 instead of bytes/string.
Common situations: Wrong column mapped to a SimpleDates field; DB array types like date[] instead of a JSON array column; driver decoding jsonb into a native type rather than bytes.
Related errors
- KitchenTime: unknown type of: %T
- SimpleDate: unknown type of: %T
- kitchen time: convert to time notation first: %w
- %s: %w
- %w: example: %s
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/b0996924b973b7bf.
Report an issue: GitHub.