prestodb/presto · error · PrestoException
${message} (user-supplied message thrown with user-supplied
Error message
${message} (user-supplied message thrown with user-supplied error code via fail() function) What it means
This overload fail(integer errorCode, varchar message) throws a PrestoException with the caller-chosen StandardErrorCode and message. The thrown error's message is exactly the user-supplied string; the code is whatever numeric StandardErrorCode matched.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/FailureFunction.java:80
@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()) {
if (standardErrorCode.toErrorCode().getCode() == errorCode) {
throw new PrestoException(standardErrorCode, message.toStringUtf8());
}
}
throw new PrestoException(StandardErrorCode.GENERIC_INTERNAL_ERROR, "Unable to find error for code: " + errorCode);
}
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Fix the condition that caused the fail() call to evaluate.
- Choose a more appropriate StandardErrorCode if the classification is wrong (e.g. INVALID_FUNCTION_ARGUMENT).
- If no specific code is needed, use the simpler fail(varchar) which always yields GENERIC_USER_ERROR.
Example fix
// before SELECT fail(65536, 'bad row: ' || id) // after -- fix upstream data so fail() is not reached
Defensive patterns
Strategy: validation
Validate before calling
-- ensure the code argument is a valid StandardErrorCode before use SELECT CASE WHEN code = 65536 THEN fail(code, msg) ELSE fail(65536, msg) END
Prevention
- Keep a whitelist of valid numeric error codes in application config
- Test fail() calls against a non-production coordinator
- Match error codes to retry/alert semantics downstream
When it happens
Trigger: Calling fail(65536, 'my message') (or any valid numeric code) in SQL; the message is thrown under the matched code.
Common situations: Pipelines that want errors classified with specific Presto error codes for downstream alerting/retry logic; test harnesses verifying error-code behavior; manual query guards with typed errors.
Related errors
- ${standardErrorCode}: failureInfo.toException() (decoded fai
- GENERIC_INTERNAL_ERROR
- INVALID_TABLE_PROPERTY
- Invalid time from server:
- Expected column to be a time type but is
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/9b59772a20fabdee.
Report an issue: GitHub.