{"record":{"id":"b6a7638699820f5d","repo":"cube-js/cube","slug":"can-t-match-args-for-func-tostring","errorCode":null,"errorMessage":"Can't match args for: ${func.toString()}","messagePattern":"Can't match args for: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/compiler/CubeSymbols.ts","lineNumber":1315,"sourceCode":"    const oldContext = this.resolveSymbolsCallContext;\n    this.resolveSymbolsCallContext = context;\n    try {\n      return func();\n    } finally {\n      this.resolveSymbolsCallContext = oldContext;\n    }\n  }\n\n  public funcArguments(func: Function): string[] {\n    const funcDefinition = func.toString();\n    if (!this.funcArgumentsValues[funcDefinition]) {\n      const match = funcDefinition.match(FunctionRegex);\n      if (match && (match[1] || match[2] || match[3])) {\n        this.funcArgumentsValues[funcDefinition] = (match[1] || match[2] || match[3]).split(',').map(s => s.trim());\n      } else if (match) {\n        this.funcArgumentsValues[funcDefinition] = [];\n      } else {\n        throw new Error(`Can't match args for: ${func.toString()}`);\n      }\n    }\n    return this.funcArgumentsValues[funcDefinition];\n  }\n\n  protected joinHints(): string | string[] | undefined {\n    const { joinHints } = this.resolveSymbolsCallContext || {};\n    if (Array.isArray(joinHints)) {\n      return R.uniq(joinHints);\n    }\n    return joinHints;\n  }\n\n  protected resolveSymbolsCallDeps(cubeName, sql) {\n    try {\n      const deps: any[] = [];\n      this.resolveSymbolsCall(sql, (name) => {\n        deps.push({ name });","sourceCodeStart":1297,"sourceCodeEnd":1333,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/compiler/CubeSymbols.ts#L1297-L1333","documentation":"When CubeSymbols parses a schema function definition to extract its named arguments, it matches the function source against a FunctionRegex (arrow/function declarations with parenthesized or single params). If the source cannot be matched at all, it throws a plain Error. This typically happens with non-standard function syntax the regex cannot parse.","triggerScenarios":"Passing a function whose serialized `toString()` output doesn't match common function syntax: bound functions (`Function.prototype.bind`), native/host functions, minified functions with unusual formatting, class methods extracted from compiled bundles, or functions produced by helper libraries that wrap user functions.","commonSituations":"Using transpiled/bundled schema code where arrow functions were rewritten to helpers; passing `myFunc.bind(null, arg)`; schemas loaded from a bundler that changes function serialization; providing a non-function or exotic callable.","solutions":["Ensure schema functions are plain, unbound arrow or `function` declarations written in the data model file itself.","Avoid `.bind()`, curried wrappers, or imported pre-built functions where Cube needs to inspect argument names.","Disable aggressive minification/transpilation for data model (schema) JS files.","If using helper-generated functions, inline the SQL or arguments explicitly instead."],"exampleFix":"// before\nconst totalFn = (price, tax) => `\\${price} + \\${tax}`;\ncube('Orders', { measures: { total: { sql: totalFn.bind(null, 'price') } } });\n// after\ncube('Orders', { measures: { total: { sql: (price, tax) => `\\${price} + \\${tax}` } } });","handlingStrategy":"type-guard","validationCode":"const src = fn.toString();\nif (!/^\\s*(async\\s+)?(function\\b|\\()/i.test(src)) {\n  throw new Error('Schema functions must be plain arrow/function declarations');\n}","typeGuard":"function isPlainSchemaFn(fn) {\n  const s = fn.toString();\n  return !s.includes('[native code]') && /^(async\\s+)?(function\\b|\\([^)]*\\)\\s*=>)/.test(s);\n}","tryCatchPattern":"try { schemaCompiler.compile(); } catch (e) { if (/Can't match args for:/.test(e.message)) { console.error('Non-plain function passed to schema; inline it'); } throw e; }","preventionTips":["Never .bind() or wrap functions used inside data models","Exclude schema files from minification/bundling","Write schema functions inline in the data model files"],"tags":["schema-compiler","function-parsing","bundling"],"backgroundTag":"function-signature-parse-failed","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}