{"record":{"id":"bd7a54782c89e177","repo":"cube-js/cube","slug":"date-range-expected-to-be-an-array-with-2-elements","errorCode":null,"errorMessage":"Date range expected to be an array with 2 elements but ${range} found","messagePattern":"Date range expected to be an array with 2 elements but (.+?) found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts","lineNumber":513,"sourceCode":"      const now = this.now();\n      return [now, now];\n    }\n    if (!dateRange[0]) {\n      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) {","sourceCodeStart":495,"sourceCodeEnd":531,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts#L495-L531","documentation":"checkDataRangeType validates that a query date range used for partitioned pre-aggregation planning is an array of exactly two elements. It throws when range is truthy but range.length !== 2, meaning an unexpected date-range shape was passed into the partition range loader. This is an input validation error on internally computed or user-supplied dateRange values.","triggerScenarios":"Passing a dateRange with 1 or 3+ elements (e.g., ['2024-01-01'] or a flattened array) into partition range loading; internal code computing intersected ranges incorrectly and passing a malformed array.","commonSituations":"Users supplying dateRange with a single date string; combining multiple time dimension ranges into an array of arrays; custom code constructing ranges programmatically; JSON payload where dateRange was mis-serialized.","solutions":["Always pass dateRange as exactly [start, end] strings, e.g. ['2024-01-01', '2024-02-01'].","For multiple ranges, use separate queries or Cube's date range intersection logic rather than concatenating arrays.","Inspect the query JSON that reached the loader and fix the client/dashboard code building the range.","Add client-side validation that Array.isArray(range) && range.length === 2 before sending."],"exampleFix":"// before\ndateRange: ['2024-01-01']\n// after\ndateRange: ['2024-01-01', '2024-03-01']","handlingStrategy":"validation","validationCode":"function isValidRangeShape(range) {\n  return Array.isArray(range) && range.length === 2;\n}\nif (!isValidRangeShape(query.timeDimensions[0].dateRange)) throw new Error('dateRange must be [start, end]');","typeGuard":"function isPairRange(r) {\n  return Array.isArray(r) && r.length === 2;\n}","tryCatchPattern":"try {\n  return await loader.loadPreAggregations();\n} catch (e) {\n  if (String(e.message).includes('expected to be an array with 2 elements')) {\n    // normalize range to [start, end] and retry\n  }\n  throw e;\n}","preventionTips":["Always send dateRange as exactly two elements.","Never concatenate multiple ranges into one array.","Centralize range construction in one validated helper.","Add schema validation on API payloads for timeDimensions."],"tags":["date-range","validation","pre-aggregation"],"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"}