prestodb/presto · error · IllegalStateException

format(format, args)

Error message

format(format, args)

What it means

assertRequest is an internal precondition helper: it throws IllegalStateException(formatting the message) whenever an expected invariant about the incoming HTTP request headers fails. The error fires for any header shape the router's request-to-session mapping does not accept.

Source

Thrown at presto-plan-checker-router-plugin/src/main/java/com/facebook/presto/router/scheduler/HttpRequestSessionContext.java:366

        }
        return properties;
    }

    private static Map<String, String> parseCredentialProperty(Map<String, List<String>> headerMap, String headerName)
    {
        Map<String, String> properties = new HashMap<>();
        for (String header : splitSessionHeader(headerMap.getOrDefault(headerName, emptyList()))) {
            List<String> nameValue = Splitter.on('=').limit(2).trimResults().splitToList(header);
            assertRequest(nameValue.size() == 2, "Invalid %s header", headerName);
            properties.put(nameValue.get(0), urlDecode(nameValue.get(1)));
        }
        return properties;
    }

    private static void assertRequest(boolean expression, String format, Object... args)
    {
        if (!expression) {
            throw new IllegalStateException(format(format, args));
        }
    }

    private static Map<String, String> parsePreparedStatementsHeaders(Map<String, List<String>> headerMap, SqlParserOptions sqlParserOptions)
    {
        ImmutableMap.Builder<String, String> preparedStatements = ImmutableMap.builder();
        for (String header : splitSessionHeader(headerMap.getOrDefault(PRESTO_PREPARED_STATEMENT, emptyList()))) {
            List<String> nameValue = Splitter.on('=').limit(2).trimResults().splitToList(header);
            assertRequest(nameValue.size() == 2, "Invalid %s header", PRESTO_PREPARED_STATEMENT);

            String statementName;
            String sqlString;
            try {
                statementName = urlDecode(nameValue.get(0));
                sqlString = urlDecode(nameValue.get(1));
            }
            catch (IllegalArgumentException e) {
                throw new IllegalArgumentException((format("Invalid %s header: %s", PRESTO_PREPARED_STATEMENT, e.getMessage())));

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Read the formatted message to identify which header failed the assertion
  2. Correct the offending X-Presto-* header on the client to match the expected name=value (or catalog.property=value) structure
  3. Compare against a known-good request from a working client to see the expected header shape
Defensive patterns

Strategy: try-catch

Try / catch

try { new HttpRequestSessionContext(request, parserOptions); }
catch (IllegalStateException | IllegalArgumentException e) { log.warn("Rejected request: {}", e.getMessage()); return Response.status(Response.Status.BAD_REQUEST).build(); }

Prevention

When it happens

Trigger: Any call to assertRequest(expression=false) during HttpRequestSessionContext construction, e.g. malformed header entries discovered while parsing prepared statements, catalog/property name parts, or other structural invariants of X-Presto-* headers.

Common situations: Proxies or clients forwarding duplicated/corrupted Presto headers, older clients sending header formats the newer router rejects, manual curl reproduction with malformed headers.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/0ac40ea19ae52347. Report an issue: GitHub.