kataras/iris · error
invalid DateRangeType given: %s
Error message
invalid DateRangeType given: %s
What it means
GetSimpleDateRange only supports WeekRange and MonthRange DateRangeType values; any other type panics with the invalid type printed via %s.
Source
Thrown at x/jsonx/simple_date.go:280
// YearRange is the date range type of a year.
YearRange DateRangeType = "year"
)
// GetSimpleDateRange returns a slice of SimpleDate between "start" and "end" pf "date"
// based on given "typ" (WeekRange, MonthRange...).
//
// Example Code:
// date := jsonx.SimpleDateFromTime(time.Now())
// dates := jsonx.GetSimpleDateRange(date, jsonx.WeekRange, time.Monday, time.Sunday)
func GetSimpleDateRange(date SimpleDate, typ DateRangeType, startWeekday, endWeekday time.Weekday) SimpleDates {
var dates []time.Time
switch typ {
case WeekRange:
dates = timex.GetWeekdays(date.ToTime(), startWeekday, endWeekday)
case MonthRange:
dates = timex.GetMonthDays(date.ToTime())
default:
panic(fmt.Sprintf("invalid DateRangeType given: %s", typ))
}
simpleDates := make(SimpleDates, len(dates))
for i, t := range dates {
simpleDates[i] = SimpleDateFromTime(t)
}
return simpleDates
}
View on GitHub (pinned to 7bedaf55a0)
Solutions
- Pass only jsonx.WeekRange or jsonx.MonthRange
- Validate/parse user input into a supported DateRangeType before calling
- Recover around the call if range types are dynamic
Example fix
// before typ := jsonx.DateRangeType(3) dates := jsonx.GetSimpleDateRange(date, typ) // panic // after dates := jsonx.GetSimpleDateRange(date, jsonx.MonthRange)
Defensive patterns
Strategy: validation
Validate before calling
func validRangeType(t jsonx.DateRangeType) bool {
return t == jsonx.WeekRange || t == jsonx.MonthRange
}
// only call GetSimpleDateRange when validRangeType(typ) Try / catch
defer func() { if r := recover(); r != nil { log.Printf("date range panic: %v", r) } }()
dates := jsonx.GetSimpleDateRange(date, typ) Prevention
- Only use the exported WeekRange/MonthRange constants
- Never use zero-value DateRangeType variables; initialize explicitly
- Validate user-supplied range names against a whitelist before mapping to the type
When it happens
Trigger: Calling jsonx.SimpleDateRangeGet (GetSimpleDateRange) with a DateRangeType other than WeekRange or MonthRange, e.g. a zero-value or custom integer.
Common situations: Declaring var typ DateRangeType without initializing (zero value not WeekRange/MonthRange); parsing a user-supplied range string into an invalid type.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- iris: switch: hosts: invalid target type: %T
- panic(err)
- panic(err)
- default configuration file '" + filename + "' does not exist
- default configuration file '<filename>' does not exist
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/e8397920c53cbc9c.
Report an issue: GitHub.