cube-js/cube · error
resultIndex is required
Error message
resultIndex is required
What it means
timeDimensionBackwardCompatibleData() converts a specific sub-result's data into a backward-compatible format (flattening old date-column layouts). It requires an explicit resultIndex into loadResponses; a undefined index is a programming error, so the library throws immediately.
Source
Thrown at packages/cubejs-client-core/src/ResultSet.ts:1142
public rawData(): T[] {
if (this.queryType !== QUERY_TYPE.REGULAR_QUERY) {
throw new Error(`Method is not supported for a '${this.queryType}' query type. Please use decompose`);
}
return this.loadResponses[0].data;
}
public annotation(): QueryAnnotations {
if (this.queryType !== QUERY_TYPE.REGULAR_QUERY) {
throw new Error(`Method is not supported for a '${this.queryType}' query type. Please use decompose`);
}
return this.loadResponses[0].annotation;
}
private timeDimensionBackwardCompatibleData(resultIndex: number) {
if (resultIndex === undefined) {
throw new Error('resultIndex is required');
}
if (!this.backwardCompatibleData[resultIndex]) {
const { data, query } = this.loadResponses[resultIndex];
const timeDimensions = (query.timeDimensions || []).filter(td => Boolean(td.granularity));
this.backwardCompatibleData[resultIndex] = data.map(row => (
{
...row,
...(
fromPairs(Object.keys(row)
.filter(
field => {
const foundTd = timeDimensions.find(d => d.dimension === field);
return foundTd && !row[ResultSet.timeDimensionMember(foundTd)];
}
).map(field => (
[ResultSet.timeDimensionMember(timeDimensions.find(d => d.dimension === field)!), row[field]]View on GitHub (pinned to 7d981676b3)
Solutions
- Pass the resultIndex explicitly (usually 0 for single-query results)
- Stop calling this private helper directly; use public APIs (chartPivot/tablePivot/seriesNames)
- If you must call it, default the argument: fn(resultIndex ?? 0)
Example fix
// before dataSet(rs.timeDimensionBackwardCompatibleData()); // after dataSet(rs.timeDimensionBackwardCompatibleData(0));
Defensive patterns
Strategy: validation
Validate before calling
function backwardCompatible(rs: ResultSet, resultIndex?: number) {
if (resultIndex === undefined) throw new TypeError('resultIndex is required');
return (rs as any).timeDimensionBackwardCompatibleData(resultIndex);
} Try / catch
let data;
try { data = helper(resultIndex); } catch (e) {
if (String(e?.message) === 'resultIndex is required') {
data = helper(0); // single-query default
} else throw e;
} Prevention
- Never call private ResultSet methods; use chartPivot/tablePivot/seriesNames
- If you must reuse internals, always pass an explicit index (0 for single queries)
- Enable strict TypeScript so missing required arguments are caught at compile time
- Pin client versions when relying on internal behavior
When it happens
Trigger: Internal call paths passing an undefined resultIndex — practically triggered by calling private/underscore-style helpers directly or by constructing/mocking a ResultSet and invoking conversion logic without the index argument (e.g. custom subclasses or copied client code).
Common situations: Monkey-patching or extending ResultSet in app code; TypeScript transpiled older client versions where helpers were called manually; copy-pasted internal logic into application utilities.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Unknown query type
- Method is not supported for a '${this.queryType}' query type
- List of references and a function are expected in form: dynR
- Last argument should be a function
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/e2d58ca5ef8117a3.
Report an issue: GitHub.