{"record":{"id":"0cbcd7ece99679b2","repo":"prestodb/presto","slug":"generic-internal-error-0cbcd7","errorCode":"GENERIC_INTERNAL_ERROR","errorMessage":"Unable to find error for code: ${errorCode}","messagePattern":"Unable to find error for code: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/FailureFunction.java","lineNumber":60,"sourceCode":"        throw new PrestoException(StandardErrorCode.GENERIC_USER_ERROR, failureInfo.toException());\n    }\n\n    // This function is only used to propagate optimization failures.\n    @Description(\"Decodes json to an exception and throws it with supplied errorCode\")\n    @ScalarFunction(value = \"fail\", visibility = HIDDEN)\n    @SqlType(\"unknown\")\n    public static boolean failWithException(\n            @SqlType(StandardTypes.INTEGER) long errorCode,\n            @SqlType(StandardTypes.JSON) Slice failureInfoSlice)\n    {\n        FailureInfo failureInfo = JSON_CODEC.fromJson(failureInfoSlice.getBytes());\n        // wrap the failure in a new exception to append the current stack trace\n        for (StandardErrorCode standardErrorCode : StandardErrorCode.values()) {\n            if (standardErrorCode.toErrorCode().getCode() == errorCode) {\n                throw new PrestoException(standardErrorCode, failureInfo.toException());\n            }\n        }\n        throw new PrestoException(StandardErrorCode.GENERIC_INTERNAL_ERROR, \"Unable to find error for code: \" + errorCode, failureInfo.toException());\n    }\n\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()) {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/FailureFunction.java#L42-L78","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Replace the errorCode argument with a valid StandardErrorCode numeric value (e.g. 65536 for GENERIC_USER_ERROR).","Look up valid codes in the StandardErrorCode enum or ErrorType documentation.","If you just need any error, use fail(varchar message) or fail(json) which do not require a code."],"exampleFix":"// before\nSELECT fail(failure_json, 12345)\n// after\nSELECT fail(failure_json, 65536) -- valid StandardErrorCode","handlingStrategy":"validation","validationCode":"-- guard before calling fail(json, code)\nSELECT CASE WHEN code IN (65536, 65540, 65541) THEN fail(failure_json, code) ELSE fail(failure_json, 65536) END","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reference documented StandardErrorCode numbers only","Use fail(varchar) or fail(json) when no specific code is needed","Parameterize codes from a maintained constants source"],"tags":["sql","presto","invalid-argument","error-code"],"backgroundTag":"invalid-argument-value","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"}