cube-js/cube · error
Date range expected to be an array with 2 elements but ${ran
Error message
Date range expected to be an array with 2 elements but ${range} found What it means
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.
Source
Thrown at packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts:513
const now = this.now();
return [now, now];
}
if (!dateRange[0]) {
return [dateRange[1], dateRange[1]];
}
if (!dateRange[1]) {
return [dateRange[0], dateRange[0]];
}
return dateRange;
}
private static checkDataRangeType(range: QueryDateRange) {
if (!range) {
return;
}
if (range.length !== 2) {
throw new Error(`Date range expected to be an array with 2 elements but ${range} found`);
}
if (typeof range[0] !== 'string' || typeof range[1] !== 'string') {
throw new Error(`Date range expected to be a string array but ${range} found`);
}
if ((range[0].length !== 23 && range[0].length !== 26) || (range[1].length !== 23 && range[0].length !== 26)) {
throw new Error(`Date range expected to be in ${DEFAULT_TS_FORMAT} format but ${range} found`);
}
}
public static intersectDateRanges(rangeA: QueryDateRange | null, rangeB: QueryDateRange | null): QueryDateRange | null {
PreAggregationPartitionRangeLoader.checkDataRangeType(rangeA);
PreAggregationPartitionRangeLoader.checkDataRangeType(rangeB);
if (!rangeB) {
return rangeA;
}
if (!rangeA) {View on GitHub (pinned to 7d981676b3)
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.
Example fix
// before dateRange: ['2024-01-01'] // after dateRange: ['2024-01-01', '2024-03-01']
Defensive patterns
Strategy: validation
Validate before calling
function isValidRangeShape(range) {
return Array.isArray(range) && range.length === 2;
}
if (!isValidRangeShape(query.timeDimensions[0].dateRange)) throw new Error('dateRange must be [start, end]'); Type guard
function isPairRange(r) {
return Array.isArray(r) && r.length === 2;
} Try / catch
try {
return await loader.loadPreAggregations();
} catch (e) {
if (String(e.message).includes('expected to be an array with 2 elements')) {
// normalize range to [start, end] and retry
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Pre-aggregation '${this.preAggregation.tableName}' requested
- Date range expected to be a string array but ${range} found
- Date range expected to be in ${DEFAULT_TS_FORMAT} format but
- Can't parse date: '${from}'
- Can't parse date: '${to}'
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/bd7a54782c89e177.
Report an issue: GitHub.