cube-js/cube · error · UserError

Python Parsing Error: ${this.errors.map(({ msg, column, line

Error message

Python Parsing Error:
${this.errors.map(({ msg, column, line }) => `${line}:${column} ${msg}`).join('\n')}

What it means

Aggregated parse-error report thrown by PythonParser.throwErrorsIfAny(). The ANTLR lexer/parser listeners collect every syntax error (message, line, column) instead of failing fast; after parsing, parsePythonAndTranspileToJs calls throwErrorsIfAny() which raises a UserError listing all errors as 'line:column msg' lines. It means the Python in the data model file is not syntactically valid.

Source

Thrown at packages/cubejs-schema-compiler/src/parser/PythonParser.ts:270

      }
    }));
  }

  public stripQuotes(text: string): string {
    if (text[0] === '"' && text[text.length - 1] === '"' || text[0] === '\'' && text[text.length - 1] === '\'') {
      return text.slice(1, text.length - 1);
    } else {
      return text;
    }
  }

  public canParse() {
    return !this.errors.length;
  }

  public throwErrorsIfAny() {
    if (this.errors.length) {
      throw new UserError(
        `Python Parsing Error:\n${this.errors.map(({ msg, column, line }) => `${line}:${column} ${msg}`).join('\n')}`
      );
    }
  }
}

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Read the line:column entries in the message and fix each reported syntax error in the Python data model file
  2. Validate the file with a real Python interpreter (python -m py_compile cubes.py) before restarting Cube
  3. Normalize indentation to consistent 4 spaces and check for missing colons/parentheses
  4. If the syntax is valid Python 3 but still rejected, check whether the embedded ANTLR grammar supports that version's features

Example fix

// before (cubes.py)
def cube_fn(x)
    return x
// after
def cube_fn(x):
    return x
Defensive patterns

Strategy: validation

Validate before calling

const { execSync } = require('child_process');
try {
  execSync('python3 -m py_compile cubes.py', { stdio: 'pipe' });
} catch (e) {
  throw new Error('cubes.py has syntax errors; fix before starting Cube');
}

Try / catch

try {
  compiler.compile();
} catch (e) {
  if (e instanceof UserError && e.message.startsWith('Python Parsing Error:')) {
    console.error(e.message); // shows line:column for each error
    process.exitCode = 1;
  } else { throw e; }
}

Prevention

When it happens

Trigger: Any call path that parses Python data-model files (parsePythonAndTranspileToJs -> throwErrorsIfAny) where the ANTLR Python3 lexer/parser recorded at least one syntaxError — e.g. bad indentation, missing colon, unbalanced quotes/parens in cubes.py.

Common situations: Syntax slips while editing Python schemas: wrong indentation (tabs vs spaces), missing ':' after def/if, stray characters, truncated files from failed saves, or Python-version-specific syntax the grammar doesn't accept.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/b62790cc3d192e2b. Report an issue: GitHub.