{"record":{"id":"9ead306378bffa60","repo":"cube-js/cube","slug":"date-range-expected-to-be-a-string-array-but-ran","errorCode":null,"errorMessage":"Date range expected to be a string array but ${range} found","messagePattern":"Date range expected to be a string array but (.+?) found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts","lineNumber":517,"sourceCode":"      return [dateRange[1], dateRange[1]];\n    }\n    if (!dateRange[1]) {\n      return [dateRange[0], dateRange[0]];\n    }\n    return dateRange;\n  }\n\n  private static checkDataRangeType(range: QueryDateRange) {\n    if (!range) {\n      return;\n    }\n\n    if (range.length !== 2) {\n      throw new Error(`Date range expected to be an array with 2 elements but ${range} found`);\n    }\n\n    if (typeof range[0] !== 'string' || typeof range[1] !== 'string') {\n      throw new Error(`Date range expected to be a string array but ${range} found`);\n    }\n\n    if ((range[0].length !== 23 && range[0].length !== 26) || (range[1].length !== 23 && range[0].length !== 26)) {\n      throw new Error(`Date range expected to be in ${DEFAULT_TS_FORMAT} format but ${range} found`);\n    }\n  }\n\n  public static intersectDateRanges(rangeA: QueryDateRange | null, rangeB: QueryDateRange | null): QueryDateRange | null {\n    PreAggregationPartitionRangeLoader.checkDataRangeType(rangeA);\n    PreAggregationPartitionRangeLoader.checkDataRangeType(rangeB);\n    if (!rangeB) {\n      return rangeA;\n    }\n    if (!rangeA) {\n      return rangeB;\n    }\n    const from = rangeA[0] > rangeB[0] ? rangeA[0] : rangeB[0];\n    const to = rangeA[1] < rangeB[1] ? rangeA[1] : rangeB[1];","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts#L499-L535","documentation":"After checking array length, checkDataRangeType requires both range endpoints to be strings. It throws when either range[0] or range[1] is not a string (e.g., a Date object, number timestamp, or null). Partition range planning expects normalized string timestamps, so non-string ranges are rejected early with a descriptive message.","triggerScenarios":"Passing JavaScript Date objects or numeric epochs in dateRange to a query handled by the partition range loader; a range where one endpoint is null/undefined; client code sending mixed types like ['2024-01-01', null].","commonSituations":"Using new Date() directly in dateRange instead of .toISOString(); serialization converting one endpoint to a number; template code filling in only one endpoint.","solutions":["Convert endpoints to ISO strings: [start.toISOString(), end.toISOString()].","Validate both endpoints are typeof 'string' before calling the query/pre-aggregation API.","If using the REST API, ensure dateRange is serialized as an array of two strings.","Normalize the range through a helper that formats dates consistently (yyyy-mm-dd or full timestamp)."],"exampleFix":"// before\ndateRange: [new Date('2024-01-01'), new Date('2024-02-01')]\n// after\ndateRange: [new Date('2024-01-01').toISOString(), new Date('2024-02-01').toISOString()]","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isStringPairRange(r) {\n  return Array.isArray(r) && r.length === 2 &&\n    typeof r[0] === 'string' && typeof r[1] === 'string';\n}\nif (!isStringPairRange(range)) throw new Error('dateRange must be an array of two strings');","tryCatchPattern":"try {\n  return await loader.loadPreAggregations();\n} catch (e) {\n  if (String(e.message).includes('expected to be a string array')) {\n    // coerce Date/number endpoints to strings and retry\n  }\n  throw e;\n}","preventionTips":["Never pass Date objects or epoch numbers as dateRange endpoints.","Call toISOString() (or equivalent) before sending ranges.","Reject null/undefined endpoints at client construction time.","Type your query builders so dateRange is typed as [string, string]."],"tags":["date-range","type-mismatch","validation"],"backgroundTag":"invalid-date-range-format","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}