{"record":{"id":"441debde84d56ea6","repo":"cube-js/cube","slug":"list-of-references-and-a-function-are-expected-in","errorCode":null,"errorMessage":"List of references and a function are expected in form: dynRef('ref', (r) => (...))","messagePattern":"List of references and a function are expected in form: dynRef\\('ref', \\(r\\) => \\(\\.\\.\\.\\)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/extensions/Reflection.ts","lineNumber":8,"sourceCode":"import R from 'ramda';\nimport { DynamicReference } from '../compiler/DynamicReference';\nimport { AbstractExtension } from './extension.abstract';\n\nexport class Reflection extends AbstractExtension {\n  public dynRef = (...args) => {\n    if (args.length < 2) {\n      throw new Error('List of references and a function are expected in form: dynRef(\\'ref\\', (r) => (...))');\n    }\n\n    const references = R.dropLast(1, args);\n    const fn = args[args.length - 1];\n\n    if (typeof fn !== 'function') {\n      throw new Error('Last argument should be a function');\n    }\n\n    return new DynamicReference(references, fn);\n  };\n}\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/extensions/Reflection.ts#L1-L21","documentation":"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.","triggerScenarios":"Calling dynRef() with no arguments, a single argument, or spreading an empty/one-element array into dynRef.","commonSituations":"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.","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"],"exampleFix":"// before\ndynRef((r) => r('users.count'));\n// after\ndynRef('users', (r) => r('users.count'));","handlingStrategy":"validation","validationCode":"const canCallDynRef = (...args) => args.length >= 2;","typeGuard":"const canCallDynRef = (...args) => args.length >= 2 && args.length - 1 >= 1;","tryCatchPattern":"try {\n  const ref = reflection.dynRef(...dynRefArgs);\n} catch (e) {\n  if (e.message.includes('dynRef')) {\n    console.error(\"Call dynRef('ref', (r) => (...)) with at least one reference and a function\");\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["dynamic-reference","extension","argument-validation"],"backgroundTag":"invalid-argument","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}