kataras/iris · error

DayTime: unknown type of: %T

Error message

DayTime: unknown type of: %T

What it means

jsonx.DayTime implements sql.driver's Scanner; Scan accepts src of type time.Time, string, or nil (and treats "null"/empty strings as zero time). Any other driver source type hits this default branch and errors, naming the concrete type. It means the database column's driver returned a value in a form DayTime cannot interpret.

Source

Thrown at x/jsonx/day_time.go:96

// Scan completes the sql driver.Scanner interface.
func (t *DayTime) 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 = DayTime(v)
	case string:
		tt, err := ParseDayTime(v)
		if err != nil {
			return err
		}
		*t = tt
	case nil:
		*t = DayTime(time.Time{})
	default:
		return fmt.Errorf("DayTime: unknown type of: %T", v)
	}

	return nil
}

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Change the DB column to a time/timestamp type so the driver returns time.Time, or keep it a text type whose driver returns string.
  2. Adjust driver/DSN settings (e.g. MySQL: ensure consistent types; check columnsAsStrings-type options) so text columns surface as string.
  3. Scan into an intermediate *string or *[]byte yourself and convert with jsonx.ParseDayTime before assigning to DayTime.
  4. Inspect the %T in the error to see exactly which driver type is returned, then handle that case in your scan wrapper.

Example fix

// before: driver returns []byte for TEXT column
var dt jsonx.DayTime
row.Scan(&dt) // DayTime: unknown type of: []byte

// after
var raw []byte
row.Scan(&raw)
dt, err := jsonx.ParseDayTime(string(raw))
Defensive patterns

Strategy: validation

Validate before calling

func scanDayTime(row *sql.Row) (jsonx.DayTime, error) {
    var raw sql.NullString
    if err := row.Scan(&raw); err != nil { return jsonx.DayTime{}, err }
    if !raw.Valid { return jsonx.DayTime{}, nil }
    return jsonx.ParseDayTime(raw.String)
}

Type guard

func canScanDayTime(src any) bool {
    switch src.(type) {
    case time.Time, string, nil:
        return true
    case []byte:
        return false // DayTime.Scan does not accept []byte; convert first
    }
    return false
}

Try / catch

if err := rows.Scan(&dt); err != nil {
    if strings.Contains(err.Error(), "DayTime: unknown type of:") {
        // re-scan into []byte/string and parse via jsonx.ParseDayTime
    }
}

Prevention

When it happens

Trigger: Scanning a database column into a jsonx.DayTime field where the driver returns e.g. []byte (some MySQL/SQLite configs return TEXT as []byte), time for a non-timestamp column type, an int (unix epoch), or a driver-specific type. Happens when the column is CHAR/VARCHAR/TEXT and the driver yields []byte instead of string.

Common situations: Column stored as TEXT in MySQL/MariaDB where the driver returns []byte for text values; column type changed from TIME/TIMESTAMP to VARCHAR (or vice versa) and the driver now delivers an unexpected Go type; using a driver or DSN setting (e.g. interpolateParams/parseTime flags) that changes returned types.

Related errors


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