{"record":{"id":"82bb085d8ef98bc5","repo":"cube-js/cube","slug":"syntax-error-during-file-filename-parsing","errorCode":null,"errorMessage":"Syntax error during '${file.fileName}' parsing: ${error.message}:\n${line}\n${spaces}^","messagePattern":"Syntax error during '(.+?)' parsing: (.+?):\n(.+?)\n(.+?)\\^","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/compiler/converters/CubeSchemaConverter.ts","lineNumber":156,"sourceCode":"          }\n        }\n      },\n    });\n  }\n\n  protected parseJS(file: SchemaFile) {\n    try {\n      return parse(file.content, {\n        sourceFilename: file.fileName,\n        sourceType: 'module',\n        plugins: ['objectRestSpread'],\n      });\n    } catch (error: any) {\n      if (error.toString().indexOf('SyntaxError') !== -1) {\n        const line = file.content.split('\\n')[error.loc.line - 1];\n        const spaces = Array(error.loc.column).fill(' ').join('');\n\n        throw new Error(`Syntax error during '${file.fileName}' parsing: ${error.message}:\\n${line}\\n${spaces}^`);\n      }\n\n      throw error;\n    }\n  }\n\n  public async generate(cubeName?: string) {\n    await this.prepare(cubeName);\n\n    this.converters.forEach((converter) => {\n      converter.convert(this.parsedFiles);\n    });\n  }\n\n  public getSourceFiles() {\n    return Object.entries(this.parsedFiles).map(([cubeName, file]) => {\n      const source = 'ast' in file\n        ? generator(file.ast, {}).code","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/compiler/converters/CubeSchemaConverter.ts#L138-L174","documentation":"When the JS parser fails with a SyntaxError while compiling a schema file, Cube re-throws with a message that includes the file name, the parser message, the offending source line, and a caret pointing at the error column. This is a wrapped parser error to make the location human-readable.","triggerScenarios":"Any syntactically invalid JavaScript in a .js data model file under the schema directory — missing brackets/commas, stray keywords, invalid syntax — processed by CubeSchemaConverter.parseJS.","commonSituations":"Typos while editing schema files; merging branches with conflicting edits; paste errors leaving truncated code; using syntax unsupported by the parser version.","solutions":["Read the caret position in the message to find the exact file, line, and column","Fix the syntax problem on the reported line (usually a missing brace, comma, or parenthesis)","Run the file through node --check or your editor's linter to validate the whole file","Check git diff for recently edited schema files if the error appeared after a merge"],"exampleFix":"// before (SyntaxError: missing comma)\ncube('orders', {\n  sql: () => `SELECT * FROM orders`\n  measures: { count: { type: 'count' } }\n});\n// after\ncube('orders', {\n  sql: () => `SELECT * FROM orders`,\n  measures: { count: { type: 'count' } }\n});","handlingStrategy":"try-catch","validationCode":"// check schema files before compiling\nconst { execSync } = require('child_process');\nexecSync(`node --check ${schemaFilePath}`);","typeGuard":null,"tryCatchPattern":"try {\n  await compiler.compile();\n} catch (e) {\n  if (e.message.startsWith('Syntax error during')) {\n    // message already contains file, line, and caret — surface it verbatim\n    console.error(e.message);\n    process.exitCode = 1;\n    return;\n  }\n  throw e;\n}","preventionTips":["Run a linter (ESLint) or editor syntax highlighting on schema .js files","Validate schema files with node --check in CI","Review schema diffs carefully after merges"],"tags":["javascript","syntax-error","schema"],"backgroundTag":"javascript-syntax-error","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}