{"record":{"id":"caca40489464a6af","repo":"prestodb/presto","slug":"generic-internal-error-caca40","errorCode":"GENERIC_INTERNAL_ERROR","errorMessage":"Formatted query does not parse: ","messagePattern":"Formatted query does not parse: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/SqlFormatterUtil.java","lineNumber":44,"sourceCode":"import static com.facebook.presto.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;\nimport static com.facebook.presto.sql.parser.ParsingOptions.DecimalLiteralTreatment.REJECT;\n\npublic final class SqlFormatterUtil\n{\n    private SqlFormatterUtil() {}\n\n    public static String getFormattedSql(Statement statement, SqlParser sqlParser, Optional<List<Expression>> parameters)\n    {\n        String sql = SqlFormatter.formatSql(statement, parameters);\n\n        // verify round-trip\n        Statement parsed;\n        try {\n            ParsingOptions parsingOptions = new ParsingOptions(REJECT /* formatted SQL should be unambiguous */);\n            parsed = sqlParser.createStatement(sql, parsingOptions);\n        }\n        catch (ParsingException e) {\n            throw new PrestoException(GENERIC_INTERNAL_ERROR, \"Formatted query does not parse: \" + statement);\n        }\n        if (!statement.equals(parsed)) {\n            throw new PrestoException(GENERIC_INTERNAL_ERROR, \"Query does not round-trip: \" + statement);\n        }\n\n        return sql;\n    }\n}\n","sourceCodeStart":26,"sourceCodeEnd":53,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/SqlFormatterUtil.java#L26-L53","documentation":"Thrown by SqlFormatterUtil.getFormattedSql after it formats a Statement back to SQL and attempts to re-parse it with strict (REJECT) parsing options. If the formatted string does not parse, the formatter produced invalid SQL, indicating a bug in the SQL formatter or an unsupported syntax, so GENERIC_INTERNAL_ERROR is raised.","triggerScenarios":"Calling SqlFormatterUtil.getFormattedSql(statement, sqlParser, ...) where statement.format(sqlFormatter) yields text that ParsingException-rejects under ParsingOptions(REJECT), e.g. formatting a node type the formatter handles incorrectly.","commonSituations":"Presto bug in SqlFormatter for newer/edge-case AST nodes; custom statements built programmatically; calling the util on statements the formatter was never designed to emit round-trippably.","solutions":["Verify with a minimal repro and file/inspect a Presto bug against the SQL formatter for that statement type","Work around by formatting with the non-strict formatter (sqlFormatter.formatStatement) instead of relying on getFormattedSql","Upgrade Presto to a version where the formatter bug for that node type is fixed","Avoid calling getFormattedSql on programmatically constructed statements that don't originate from parsing"],"exampleFix":"// before\nString sql = SqlFormatterUtil.getFormattedSql(statement, sqlParser);\n// after\nString sql = sqlFormatter.formatStatement(statement); // if strict round-trip not required","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { String sql = SqlFormatterUtil.getFormattedSql(statement, sqlParser); } catch (PrestoException e) { if (e.getErrorCode().getCode() == GENERIC_INTERNAL_ERROR.toErrorCode().getCode()) { return sqlParser + fallback: sqlFormatter.formatStatement(statement); } throw e; }","preventionTips":["Only call getFormattedSql on statements produced by the parser","Pin/upgrade Presto versions with formatter fixes","Report formatter bugs with minimal repros","Prefer sqlFormatter.formatStatement when strict round-trip isn't required"],"tags":["sql","formatter","internal-error","presto"],"backgroundTag":"internal-invariant-violation","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}