cube-js/cube · error · Error
List of references and a function are expected in form: dynR
Error message
List of references and a function are expected in form: dynRef('ref', (r) => (...)) What it means
The dynRef extension helper creates a DynamicReference and requires at least two arguments: one or more reference names plus a generating function. It throws when fewer than two arguments are supplied, because there would be no function to evaluate the reference with.
Source
Thrown at packages/cubejs-schema-compiler/src/extensions/Reflection.ts:8
import R from 'ramda';
import { DynamicReference } from '../compiler/DynamicReference';
import { AbstractExtension } from './extension.abstract';
export class Reflection extends AbstractExtension {
public dynRef = (...args) => {
if (args.length < 2) {
throw new Error('List of references and a function are expected in form: dynRef(\'ref\', (r) => (...))');
}
const references = R.dropLast(1, args);
const fn = args[args.length - 1];
if (typeof fn !== 'function') {
throw new Error('Last argument should be a function');
}
return new DynamicReference(references, fn);
};
}
View on GitHub (pinned to 7d981676b3)
Solutions
- Call dynRef with at least one reference string followed by a function: dynRef('ref', (r) => ...)
- If args are built dynamically, append the generator function as the last element before spreading
- Check for accidental typos like dynRef('ref') missing the callback
Example fix
// before
dynRef((r) => r('users.count'));
// after
dynRef('users', (r) => r('users.count')); Defensive patterns
Strategy: validation
Validate before calling
const canCallDynRef = (...args) => args.length >= 2;
Type guard
const canCallDynRef = (...args) => args.length >= 2 && args.length - 1 >= 1;
Try / catch
try {
const ref = reflection.dynRef(...dynRefArgs);
} catch (e) {
if (e.message.includes('dynRef')) {
console.error("Call dynRef('ref', (r) => (...)) with at least one reference and a function");
}
throw e;
} Prevention
- Remember the signature: dynRef(name1, ..., fn) — fn is always last
- When spreading arrays, push the generator function as the last element
- Write the callback inline rather than conditionally
When it happens
Trigger: Calling dynRef() with no arguments, a single argument, or spreading an empty/one-element array into dynRef.
Common situations: Building dynRef calls programmatically and spreading an array without the function; misreading the signature as dynRef(fn) instead of dynRef('ref', fn); refactors that dropped the reference name argument.
Understand the failure class
Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.
Related errors
- Last argument should be a function
- resultIndex is required
- userId.sql is not defined
- time.sql is not defined
- steps are not defined
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/441debde84d56ea6.
Report an issue: GitHub.