prestodb/presto · error · PrestoException

${standardErrorCode}: failureInfo.toException() (decoded fai

Error message

${standardErrorCode}: failureInfo.toException() (decoded failure rethrown with supplied error code via fail() function)

What it means

This overload of the hidden fail(json, code) function decodes a FailureInfo from JSON and re-throws it wrapped in a PrestoException using the caller-supplied StandardErrorCode. It allows an error captured during one phase to be re-raised with a specific error code chosen by the caller.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/FailureFunction.java:57

    {
        FailureInfo failureInfo = JSON_CODEC.fromJson(failureInfoSlice.getBytes());
        // wrap the failure in a new exception to append the current stack trace
        throw new PrestoException(StandardErrorCode.GENERIC_USER_ERROR, failureInfo.toException());
    }

    // This function is only used to propagate optimization failures.
    @Description("Decodes json to an exception and throws it with supplied errorCode")
    @ScalarFunction(value = "fail", visibility = HIDDEN)
    @SqlType("unknown")
    public static boolean failWithException(
            @SqlType(StandardTypes.INTEGER) long errorCode,
            @SqlType(StandardTypes.JSON) Slice failureInfoSlice)
    {
        FailureInfo failureInfo = JSON_CODEC.fromJson(failureInfoSlice.getBytes());
        // wrap the failure in a new exception to append the current stack trace
        for (StandardErrorCode standardErrorCode : StandardErrorCode.values()) {
            if (standardErrorCode.toErrorCode().getCode() == errorCode) {
                throw new PrestoException(standardErrorCode, failureInfo.toException());
            }
        }
        throw new PrestoException(StandardErrorCode.GENERIC_INTERNAL_ERROR, "Unable to find error for code: " + errorCode, failureInfo.toException());
    }

    @Description("Throws an exception with a given message")
    @ScalarFunction(value = "fail", visibility = HIDDEN)
    @SqlType("unknown")
    public static boolean fail(@SqlType(StandardTypes.VARCHAR) Slice message)
    {
        throw new PrestoException(StandardErrorCode.GENERIC_USER_ERROR, message.toStringUtf8());
    }

    @Description("Throws an exception with a given error code and message")
    @ScalarFunction(value = "fail", visibility = HIDDEN)
    @SqlType("unknown")
    public static boolean fail(
            @SqlType(StandardTypes.INTEGER) long errorCode,

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Inspect the inner decoded exception to fix the original problem.
  2. Verify the numeric errorCode passed corresponds to the intended StandardErrorCode.
  3. If you only want a generic user error, use the single-argument fail(json) form instead.

Example fix

// before
SELECT fail(failure_json, 999999)
// after
SELECT fail(failure_json, 65536) -- GENERIC_USER_ERROR
Defensive patterns

Strategy: validation

Validate before calling

// caller-side check before invoking fail(json, code)
boolean isValidCode = java.util.Arrays.stream(StandardErrorCode.values())
    .anyMatch(c -> c.toErrorCode().getCode() == suppliedCode);

Prevention

When it happens

Trigger: Calling fail(json_failure_info, integer_error_code) where errorCode matches a valid StandardErrorCode value; the decoded exception is thrown under that code.

Common situations: Seen when engine-internal code defers a failure and rethrows it with a computed code, or when a developer calls fail() manually with a serialized failure and a numeric code such as 65536 (GENERIC_USER_ERROR).

Related errors


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