kataras/iris · warning

%s, %w

Error message

%s, %w

What it means

strParseSimpleDate tries two accepted date layouts; if both fail it returns a wrapped error containing both parse failure messages. The error tells you the value did not match either supported simple-date layout.

Source

Thrown at context/strconv.go:203

	return result, nil
}

func strParseTime(layout, value string) (time.Time, error) {
	return time.Parse(layout, value)
}

const (
	simpleDateLayout1 = "2006/01/02"
	simpleDateLayout2 = "2006-01-02"
)

func strParseSimpleDate(value string) (time.Time, error) {
	t1, err := strParseTime(simpleDateLayout1, value)
	if err != nil {
		t2, err2 := strParseTime(simpleDateLayout2, value)
		if err2 != nil {
			return time.Time{}, fmt.Errorf("%s, %w", err.Error(), err2)
		}

		return t2, nil
	}

	return t1, nil
}

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Check the library's accepted simple date layouts and format the input accordingly before posting it (e.g. send "2024-01-05" style values).
  2. Trim/validate the input; if the value may be empty, check form presence before calling PostValueSimpleDate.
  3. Parse the raw string yourself with time.Parse using the layouts you need, then use the generic PostValue API.
  4. Handle the returned error and return 400 to the client with a message naming the expected format.

Example fix

// before
v := ctx.PostValueSimpleDate("date") // "2024-01-05T10:00:00Z" -> error
// after
raw := strings.TrimSpace(ctx.PostValue("date"))
if len(raw) > 10 { raw = raw[:10] } // keep only YYYY-MM-DD
d, _ := time.Parse("2006-01-02", raw)
Defensive patterns

Strategy: try-catch

Validate before calling

raw := strings.TrimSpace(input)
if _, err := time.Parse("2006-01-02", raw); err != nil {
    return errors.New("date must be in YYYY-MM-DD format")
}

Try / catch

d, err := ctx.PostValueSimpleDate("date")
if err != nil {
    http.Error(w, "expected simple date format", http.StatusBadRequest)
    return
}

Prevention

When it happens

Trigger: Calling PostValueSimpleDate on a Context (or indirectly strParseSimpleDate) with a string not matching simpleDateLayout1 or simpleDateLayout2 — e.g. "2024-01-05T10:00:00Z", "01/05/2024", or an empty value from a missing form field.

Common situations: Client sends RFC3339 timestamps instead of a plain date; form field omitted so empty string parsed; locale-formatted dates ("05/01/2024"); extra whitespace in the input.

Related errors


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