{"record":{"id":"4d07d4792c62f712","repo":"zincsearch/zincsearch","slug":"illegal-argument-exception","errorCode":"illegal_argument_exception","errorMessage":"[date_range] range value from parse err %s","messagePattern":"\\[date_range\\] range value from parse err (.+?)","errorType":"validation","errorClass":"errors.Error","httpStatus":null,"severity":"error","filePath":"pkg/uquery/aggregation/aggregation.go","lineNumber":132,"sourceCode":"\t\t\t\tformat = agg.DateRange.Format\n\t\t\t}\n\t\t\ttimeZone := time.UTC\n\t\t\tif agg.DateRange.TimeZone != \"\" {\n\t\t\t\ttimeZone, err = zutils.ParseTimeZone(agg.DateRange.TimeZone)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn errors.New(errors.ErrorTypeXContentParseException, fmt.Sprintf(\"[date_range] time_zone parse err %s\", err.Error()))\n\t\t\t\t}\n\t\t\t}\n\t\t\tswitch prop.Type {\n\t\t\tcase \"date\", \"time\":\n\t\t\t\tsubreq = aggregations.DateRanges(search.Field(agg.DateRange.Field))\n\t\t\t\tfor _, v := range agg.DateRange.Ranges {\n\t\t\t\t\tfrom := time.Time{}\n\t\t\t\t\tto := time.Time{}\n\t\t\t\t\tif v.From != \"\" {\n\t\t\t\t\t\tfrom, err = time.ParseInLocation(format, v.From, timeZone)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn errors.New(errors.ErrorTypeIllegalArgumentException, fmt.Sprintf(\"[date_range] range value from parse err %s\", err.Error()))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif v.To != \"\" {\n\t\t\t\t\t\tto, err = time.ParseInLocation(format, v.To, timeZone)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn errors.New(errors.ErrorTypeIllegalArgumentException, fmt.Sprintf(\"[date_range] range value to parse err %s\", err.Error()))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tsubreq.AddRange(aggregations.NewDateRange(from, to))\n\t\t\t\t}\n\t\t\t\treq.AddAggregation(name, subreq)\n\t\t\tdefault:\n\t\t\t\treturn errors.New(errors.ErrorTypeParsingException, \"[date_range] aggregation only support type datetime\")\n\t\t\t}\n\t\tcase agg.Histogram != nil:\n\t\t\tif agg.Histogram.Size == 0 {\n\t\t\t\tagg.Histogram.Size = config.Global.AggregationTermsSize\n\t\t\t}","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/zincsearch/zincsearch/blob/dd2f8afd6562d4d52c41b2c5d312280e684a25ba/pkg/uquery/aggregation/aggregation.go#L114-L150","documentation":"Each date_range \"from\" value is parsed with time.ParseInLocation using the resolved format (field format, agg format, or RFC3339). An unparsable from string yields an illegal_argument_exception wrapping the underlying time-parse error.","triggerScenarios":"date_range ranges entry with from set to a string that doesn't match the effective format — e.g. \"2024/01/01\" when the format is RFC3339, or epoch-millis numbers as strings when format expects a date layout.","commonSituations":"Sending epoch timestamps while the format is a date layout; dates without timezone info against RFC3339; mismatch between the field's declared format and the values supplied; locale-formatted dates.","solutions":["Supply from values matching the effective format (default RFC3339, e.g. \"2024-01-01T00:00:00Z\")","Set an explicit \"format\" on the date_range agg matching your input values","Use the field's mapped format and send values in that layout"],"exampleFix":"// before\n{\"date_range\":{\"field\":\"@timestamp\",\"ranges\":[{\"from\":\"2024-01-01\"}]}}\n// after\n{\"date_range\":{\"field\":\"@timestamp\",\"ranges\":[{\"from\":\"2024-01-01T00:00:00Z\"}]}}","handlingStrategy":"validation","validationCode":"const fmt = agg.format ?? 'YYYY-MM-DDTHH:mm:ssZ'; // RFC3339 default\nfor (const r of ranges) {\n  if (r.from && Number.isNaN(Date.parse(r.from))) {\n    throw new Error(`date_range 'from' not RFC3339-parseable: ${r.from}`);\n  }\n}","typeGuard":"function isParseableDate(s) {\n  return typeof s === 'string' && !Number.isNaN(Date.parse(s));\n}","tryCatchPattern":"try {\n  return await search(query);\n} catch (e) {\n  if (e.code === 'illegal_argument_exception' && e.message.includes('range value from parse err')) {\n    console.error('from bound does not match expected date format; use RFC3339 or set format');\n  }\n  throw e;\n}","preventionTips":["Emit all range bounds in RFC3339 (e.g. new Date().toISOString())","Set an explicit format on the aggregation matching your input layout","Avoid epoch-millis strings unless the format accepts them","Validate bounds with Date.parse before sending"],"tags":["aggregation","date-range","date-parsing"],"backgroundTag":"date-parse-error","analyzedSha":"dd2f8afd6562d4d52c41b2c5d312280e684a25ba","analyzedAt":"2026-09-03T00:22:38.551Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}