{"record":{"id":"e8397920c53cbc9c","repo":"kataras/iris","slug":"invalid-daterangetype-given-s","errorCode":null,"errorMessage":"invalid DateRangeType given: %s","messagePattern":"invalid DateRangeType given: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/jsonx/simple_date.go","lineNumber":280,"sourceCode":"\t// YearRange is the date range type of a year.\n\tYearRange DateRangeType = \"year\"\n)\n\n// GetSimpleDateRange returns a slice of SimpleDate between \"start\" and \"end\" pf \"date\"\n// based on given \"typ\" (WeekRange, MonthRange...).\n//\n// Example Code:\n// date := jsonx.SimpleDateFromTime(time.Now())\n// dates := jsonx.GetSimpleDateRange(date, jsonx.WeekRange, time.Monday, time.Sunday)\nfunc GetSimpleDateRange(date SimpleDate, typ DateRangeType, startWeekday, endWeekday time.Weekday) SimpleDates {\n\tvar dates []time.Time\n\tswitch typ {\n\tcase WeekRange:\n\t\tdates = timex.GetWeekdays(date.ToTime(), startWeekday, endWeekday)\n\tcase MonthRange:\n\t\tdates = timex.GetMonthDays(date.ToTime())\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"invalid DateRangeType given: %s\", typ))\n\t}\n\n\tsimpleDates := make(SimpleDates, len(dates))\n\tfor i, t := range dates {\n\t\tsimpleDates[i] = SimpleDateFromTime(t)\n\t}\n\n\treturn simpleDates\n}\n","sourceCodeStart":262,"sourceCodeEnd":290,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/jsonx/simple_date.go#L262-L290","documentation":"GetSimpleDateRange only supports WeekRange and MonthRange DateRangeType values; any other type panics with the invalid type printed via %s.","triggerScenarios":"Calling jsonx.SimpleDateRangeGet (GetSimpleDateRange) with a DateRangeType other than WeekRange or MonthRange, e.g. a zero-value or custom integer.","commonSituations":"Declaring var typ DateRangeType without initializing (zero value not WeekRange/MonthRange); parsing a user-supplied range string into an invalid type.","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"],"exampleFix":"// before\ntyp := jsonx.DateRangeType(3)\ndates := jsonx.GetSimpleDateRange(date, typ) // panic\n// after\ndates := jsonx.GetSimpleDateRange(date, jsonx.MonthRange)","handlingStrategy":"validation","validationCode":"func validRangeType(t jsonx.DateRangeType) bool {\n    return t == jsonx.WeekRange || t == jsonx.MonthRange\n}\n// only call GetSimpleDateRange when validRangeType(typ)","typeGuard":null,"tryCatchPattern":"defer func() { if r := recover(); r != nil { log.Printf(\"date range panic: %v\", r) } }()\ndates := jsonx.GetSimpleDateRange(date, typ)","preventionTips":["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"],"tags":["go","panic","dates","invalid-enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}