prestodb/presto · error · PrestoException

GENERIC_INTERNAL_ERROR

GENERIC_INTERNAL_ERROR

Error message

Unable to find error for code: ${errorCode}

What it means

When fail(json, code) is called with an integer that does not match any StandardErrorCode's numeric code, the function throws a GENERIC_INTERNAL_ERROR with this message instead of the intended failure. It is a guard against invalid error codes passed to the fail() function.

Source

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

        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,
            @SqlType(StandardTypes.VARCHAR) Slice message)
    {
        for (StandardErrorCode standardErrorCode : StandardErrorCode.values()) {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Replace the errorCode argument with a valid StandardErrorCode numeric value (e.g. 65536 for GENERIC_USER_ERROR).
  2. Look up valid codes in the StandardErrorCode enum or ErrorType documentation.
  3. If you just need any error, use fail(varchar message) or fail(json) which do not require a code.

Example fix

// before
SELECT fail(failure_json, 12345)
// after
SELECT fail(failure_json, 65536) -- valid StandardErrorCode
Defensive patterns

Strategy: validation

Validate before calling

-- guard before calling fail(json, code)
SELECT CASE WHEN code IN (65536, 65540, 65541) THEN fail(failure_json, code) ELSE fail(failure_json, 65536) END

Prevention

When it happens

Trigger: Calling fail(failure_json, errorCode) where errorCode is not the numeric code of any StandardErrorCode enum value (e.g. 1, 0, or an out-of-range number).

Common situations: Hand-written SQL using a made-up or misremembered error code; queries built by tooling that assumed arbitrary integer codes were valid; code constants changed between Presto versions.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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