{"record":{"id":"9b59772a20fabdee","repo":"prestodb/presto","slug":"message-user-supplied-message-thrown-with-user","errorCode":null,"errorMessage":"${message} (user-supplied message thrown with user-supplied error code via fail() function)","messagePattern":"(.+?) \\(user-supplied message thrown with user-supplied error code via fail\\(\\) function\\)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/FailureFunction.java","lineNumber":80,"sourceCode":"\n    @Description(\"Throws an exception with a given message\")\n    @ScalarFunction(value = \"fail\", visibility = HIDDEN)\n    @SqlType(\"unknown\")\n    public static boolean fail(@SqlType(StandardTypes.VARCHAR) Slice message)\n    {\n        throw new PrestoException(StandardErrorCode.GENERIC_USER_ERROR, message.toStringUtf8());\n    }\n\n    @Description(\"Throws an exception with a given error code and message\")\n    @ScalarFunction(value = \"fail\", visibility = HIDDEN)\n    @SqlType(\"unknown\")\n    public static boolean fail(\n            @SqlType(StandardTypes.INTEGER) long errorCode,\n            @SqlType(StandardTypes.VARCHAR) Slice message)\n    {\n        for (StandardErrorCode standardErrorCode : StandardErrorCode.values()) {\n            if (standardErrorCode.toErrorCode().getCode() == errorCode) {\n                throw new PrestoException(standardErrorCode, message.toStringUtf8());\n            }\n        }\n        throw new PrestoException(StandardErrorCode.GENERIC_INTERNAL_ERROR, \"Unable to find error for code: \" + errorCode);\n    }\n}\n","sourceCodeStart":62,"sourceCodeEnd":86,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/FailureFunction.java#L62-L86","documentation":"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.","triggerScenarios":"Calling fail(65536, 'my message') (or any valid numeric code) in SQL; the message is thrown under the matched code.","commonSituations":"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.","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."],"exampleFix":"// before\nSELECT fail(65536, 'bad row: ' || id)\n// after\n-- fix upstream data so fail() is not reached","handlingStrategy":"validation","validationCode":"-- ensure the code argument is a valid StandardErrorCode before use\nSELECT CASE WHEN code = 65536 THEN fail(code, msg) ELSE fail(65536, msg) END","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["sql","presto","user-error","error-code"],"backgroundTag":"user-thrown-sql-error","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"}