{"record":{"id":"e59c874b5287aad6","repo":"VictoriaMetrics/VictoriaMetrics","slug":"duration-q-must-be-in-the-range-s-s","errorCode":null,"errorMessage":"duration %q must be in the range [%s, %s]","messagePattern":"duration %q must be in the range \\[(.+?), (.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/timeutil/duration.go","lineNumber":22,"sourceCode":"\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/VictoriaMetrics/metricsql\"\n)\n\nvar (\n\tminDuration = time.Duration(minValidMilli * time.Millisecond)\n\tmaxDuration = time.Duration(maxValidMilli * time.Millisecond)\n)\n\n// ParseDuration parses duration string in Prometheus format\nfunc ParseDuration(s string) (time.Duration, error) {\n\tms, err := metricsql.DurationValue(s, 0)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tif ms < minValidMilli || maxValidMilli < ms {\n\t\treturn 0, fmt.Errorf(\"duration %q must be in the range [%s, %s]\", s, minDuration, maxDuration)\n\t}\n\treturn time.Duration(ms) * time.Millisecond, nil\n}\n","sourceCodeStart":4,"sourceCodeEnd":26,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/timeutil/duration.go#L4-L26","documentation":"lib/timeutil.ParseDuration wraps metricsql.DurationValue parsing and additionally bounds the result to the representable time.Duration range: milliseconds between minValidMilli (math.MinInt64/1e6) and maxValidMilli (math.MaxInt64/1e6), i.e. roughly -292 years .. 292 years. Durations outside that range are rejected with this error.","triggerScenarios":"Calling timeutil.ParseDuration with an oversized duration string such as `\"100000000000y\"` or an extremely large nanosecond/millisecond value (e.g. `-retentionPeriod 99999999999i`), where ms falls outside [minValidMilli, maxValidMilli].","commonSituations":"Unit mistakes (entering milliseconds where days were intended); misconfigured retention/dedup/scroll flags like -retentionPeriod or -streamAggr.keepMetricNames intervals set absurdly high; template substitution injecting a bad number.","solutions":["Lower the duration to within the supported range (about ±292 years), e.g. use `100y` instead of `1000000y`","Check the unit suffix: metricsql accepts s, m, h, d, w, y, i — make sure you did not double-scale the number","Validate flag values before launch; the error message echoes the invalid input"],"exampleFix":"// before\nParseDuration(\"100000000000y\")\n// after\nParseDuration(\"100y\")","handlingStrategy":"validation","validationCode":"const maxDur = time.Duration(math.MaxInt64/1_000_000) * time.Millisecond\nfunc safeDuration(s string) (time.Duration, error) {\n\td, err := timeutil.ParseDuration(s)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tif d > maxDur || d < -maxDur {\n\t\treturn 0, fmt.Errorf(\"duration %s out of range\", s)\n\t}\n\treturn d, nil\n}","typeGuard":null,"tryCatchPattern":"d, err := timeutil.ParseDuration(flagValue)\nif err != nil {\n\treturn fmt.Errorf(\"invalid duration flag %q: %w\", flagValue, err)\n}","preventionTips":["Clamp durations at config-load time to sane application limits","Double-check unit suffixes (y/d/h vs ms)","Reject suspiciously large numeric flags in CI"],"tags":["time","parsing","validation"],"backgroundTag":"duration-out-of-range","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}