{"record":{"id":"d972b94bd17b6d83","repo":"cube-js/cube","slug":"error-parsing-schemafile-filename","errorCode":null,"errorMessage":"Error parsing ${schemaFile.fileName}","messagePattern":"Error parsing (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/compiler/converters/CubeSchemaConverter.ts","lineNumber":127,"sourceCode":"    const ast = this.parseJS(schemaFile);\n\n    traverse(ast, {\n      CallExpression: (path) => {\n        if (t.isIdentifier(path.node.callee)) {\n          const args = path.get('arguments');\n\n          if (path.node.callee.name === 'cube') {\n            if (args?.[args.length - 1]) {\n              let cubeName: string | undefined;\n\n              if (args[0].node.type === 'StringLiteral' && args[0].node.value) {\n                cubeName = args[0].node.value;\n              } else if (args[0].node.type === 'TemplateLiteral' && args[0].node.quasis?.[0]?.value.cooked) {\n                cubeName = args[0].node.quasis?.[0]?.value.cooked;\n              }\n\n              if (cubeName == null) {\n                throw new Error(`Error parsing ${schemaFile.fileName}`);\n              }\n\n              if (t.isObjectExpression(args[1]?.node) && ast != null && (!filterCubeName || cubeName === filterCubeName)) {\n                this.parsedFiles[cubeName] = {\n                  fileName: schemaFile.fileName,\n                  ast,\n                  cubeDefinition: args[1].node,\n                };\n              }\n            }\n          }\n        }\n      },\n    });\n  }\n\n  protected parseJS(file: SchemaFile) {\n    try {","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/compiler/converters/CubeSchemaConverter.ts#L109-L145","documentation":"During JS schema compilation the converter walks the AST looking for cube() calls and tries to extract the cube's name from the first argument. If the argument is not a string or template literal with a cooked value (e.g. an identifier, concatenation, or computed expression), the cube name cannot be determined statically and it throws.","triggerScenarios":"Passing a dynamic first argument to cube() in a JS data model — a variable, string concatenation with variables, a template literal containing ${...} expressions, or cube() called with no arguments.","commonSituations":"Generating cube names programmatically (e.g. `cube(prefix + 'orders', ...)`); looping over configs to create cubes dynamically; refactoring that replaced a literal with a constant.","solutions":["Use a plain string literal as the first argument of cube(): cube('orders', {...})","If using a template literal, remove all ${} interpolations so the name is fully static","Compute the name in a separate variable only if you pass a literal — otherwise restructure to one cube() call per literal name"],"exampleFix":"// before\nconst name = 'orders';\ncube(name, { sql: () => 'SELECT 1' });\n// after\ncube('orders', { sql: () => 'SELECT 1' });","handlingStrategy":"validation","validationCode":"function assertStaticCubeName(callArgs) {\n  const a = callArgs[0];\n  if (typeof a !== 'string' || a.includes('${')) {\n    throw new Error('cube() first argument must be a static string literal');\n  }\n}","typeGuard":"const isStaticCubeName = (a) => typeof a === 'string' && !a.includes('${');","tryCatchPattern":"try {\n  await compiler.compile();\n} catch (e) {\n  if (e.message.startsWith('Error parsing ')) {\n    const file = e.message.replace('Error parsing ', '');\n    console.error(`cube() in ${file} uses a dynamic name — pass a string literal`);\n  }\n  throw e;\n}","preventionTips":["Never use variables or concatenation in the first argument of cube()","Avoid template literals with ${} in cube names","If you need many similar cubes, write each cube() call with its own literal name"],"tags":["javascript","ast","schema"],"backgroundTag":"static-analysis-dynamic-value","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}