kataras/iris · error
%s: %w
Error message
%s: %w
What it means
ParseSimpleDate tries "2006-01-02" first; if that fails it retries the zero-padded-optional Postgres layout "2006-1-2" (pgx v5.0.0-alpha.3+ returns dates like "1993-1-1"). If both parses fail, it returns the second error's text followed by the first error, as "<parse2 error>: <parse1 error>".
Source
Thrown at x/jsonx/simple_date.go:53
// - "2024-1-1"
func ParseSimpleDate(s string) (SimpleDate, error) {
if s == "" || s == "null" {
return SimpleDate{}, nil
}
var (
tt time.Time
err error
)
tt, err = time.Parse(SimpleDateLayout, s)
if err != nil {
// After v5.0.0-alpha.3 of pgx this is coming as "1993-1-1" instead of the stored
// value "1993-01-01".
var err2 error
tt, err2 = time.Parse(simpleDateLayoutPostgres, s)
if err2 != nil {
return SimpleDate{}, fmt.Errorf("%s: %w", err2.Error(), err)
}
}
return SimpleDate(tt), nil
}
// UnmarshalJSON binds the json "data" to "t" with the `SimpleDateLayout`.
func (t *SimpleDate) UnmarshalJSON(data []byte) error {
if isNull(data) {
return nil
}
data = trimQuotes(data)
dataStr := string(data)
if len(dataStr) == 0 {
return nil // do not allow empty "" on simple dates.
}
View on GitHub (pinned to 7bedaf55a0)
Solutions
- Normalize the input to YYYY-MM-DD before calling ParseSimpleDate.
- If it comes from a full timestamp, truncate: t.Format("2006-01-02") first.
- Use time.Parse with your custom layout and then convert via jsonx.SimpleDateFromTime(t).
Example fix
// before
jsonx.ParseSimpleDate("01/02/1993") // error
// after
t, _ := time.Parse("02/01/2006", "01/02/1993")
sd := jsonx.SimpleDateFromTime(t) Defensive patterns
Strategy: validation
Validate before calling
func isSimpleDateLayout(s string) bool {
_, e1 := time.Parse("2006-01-02", s)
_, e2 := time.Parse("2006-1-2", s)
return e1 == nil || e2 == nil
} Type guard
func toSimpleDate(s string) (jsonx.SimpleDate, error) {
for _, layout := range []string{"2006-01-02", "2006-1-2", "02/01/2006", "01/02/2006"} {
if t, err := time.Parse(layout, s); err == nil {
return jsonx.SimpleDateFromTime(t), nil
}
}
return jsonx.SimpleDate{}, fmt.Errorf("unsupported date format: %s", s)
} Try / catch
sd, err := jsonx.ParseSimpleDate(s)
if err != nil {
// err text contains both layout failures; log s and fall back to manual layouts
return fmt.Errorf("parse simple date %q: %w", s, err)
} Prevention
- Normalize all date inputs to YYYY-MM-DD at system boundaries
- Truncate timestamps to date before parsing
- Keep pgx versions tested; remember pgx v5 zero-padding behavior
When it happens
Trigger: Calling jsonx.ParseSimpleDate (directly or via Scan/UnmarshalJSON paths) with a string that matches neither layout — e.g. "01/02/1993", "1993-01-01 10:00", "Jan 2 2006", or non-date text.
Common situations: Reading date strings from CSV/config in a locale format (DD/MM/YYYY); DB columns typed VARCHAR containing datetime strings; passing a full RFC3339 timestamp instead of a bare date.
Related errors
- kitchen time: convert to time notation first: %w
- KitchenTime: unknown type of: %T
- SimpleDate: unknown type of: %T
- simple dates: scan: invalid type of: %T
- %w: example: %s
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/37b8eaef6aa34fa3.
Report an issue: GitHub.