kataras/iris · error

SimpleDate: unknown type of: %T

Error message

SimpleDate: unknown type of: %T

What it means

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.

Source

Thrown at x/jsonx/simple_date.go:174

// Scan completes the pg and native sql driver.Scanner interface
// reading functionality of a custom type.
func (t *SimpleDate) Scan(src any) error {
	switch v := src.(type) {
	case time.Time: // type was set to timestamp
		if v.IsZero() {
			return nil // don't set zero, ignore it.
		}
		*t = SimpleDate(v)
	case string:
		tt, err := ParseSimpleDate(v)
		if err != nil {
			return err
		}
		*t = tt
	case nil:
		*t = SimpleDate(time.Time{})
	default:
		return fmt.Errorf("SimpleDate: unknown type of: %T", v)
	}

	return nil
}

// Slice of SimpleDate.
type SimpleDates []SimpleDate

// First returns the first element of the date slice.
func (t SimpleDates) First() SimpleDate {
	if len(t) == 0 {
		return SimpleDate{}
	}

	return t[0]
}

// Last returns the last element of the date slice.

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Change the column to DATE/TIMESTAMP so the driver yields time.Time.
  2. If the type in the message is []byte, scan into *string first then call jsonx.ParseSimpleDate.
  3. Convert ints/epoch to time.Time before scanning.

Example fix

// before
var sd jsonx.SimpleDate
rows.Scan(&sd) // src is []byte -> error
// after
var raw string
rows.Scan(&raw)
sd, _ = jsonx.ParseSimpleDate(raw)
Defensive patterns

Strategy: type-guard

Validate before calling

func canScanSimpleDate(src any) bool {
	switch src.(type) {
	case nil, time.Time, string:
		return true
	}
	return false
}

Type guard

func knownSimpleDateSrc(src any) bool {
	switch src.(type) {
	case time.Time, string, nil:
		return true
	default:
		return false
	}
}

Try / catch

var sd jsonx.SimpleDate
if err := rows.Scan(&sd); err != nil {
	if strings.HasPrefix(err.Error(), "SimpleDate: unknown type of:") {
		var raw string
		if e2 := rows.Scan(&raw); e2 == nil {
			sd, err = jsonx.ParseSimpleDate(raw)
		}
	}
	return err
}

Prevention

When it happens

Trigger: 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.

Common situations: Postgres DATE columns through drivers returning []byte; scanning an int epoch into SimpleDate; ORM-generated scans binding the wrong column order.

Related errors


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/cdecf1bf2fa7ba18. Report an issue: GitHub.