{"record":{"id":"79fe6015eb1a9fd7","repo":"prestodb/presto","slug":"invalid-function-argument-79fe60","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Not a valid Unicode code point: ","messagePattern":"Not a valid Unicode code point: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/StringFunctions.java","lineNumber":75,"sourceCode":"\n/**\n * Current implementation is based on code points from Unicode and does ignore grapheme cluster boundaries.\n * Therefore only some methods work correctly with grapheme cluster boundaries.\n */\npublic final class StringFunctions\n{\n    private StringFunctions() {}\n\n    @Description(\"convert Unicode code point to a string\")\n    @ScalarFunction\n    @SqlType(\"varchar(1)\")\n    public static Slice chr(@SqlType(StandardTypes.BIGINT) long codepoint)\n    {\n        try {\n            return SliceUtf8.codePointToUtf8(Ints.saturatedCast(codepoint));\n        }\n        catch (InvalidCodePointException e) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Not a valid Unicode code point: \" + codepoint, e);\n        }\n    }\n\n    @Description(\"returns Unicode code point of a single character string\")\n    @ScalarFunction(\"codepoint\")\n    @SqlType(StandardTypes.INTEGER)\n    public static long codepoint(@SqlType(\"varchar(1)\") Slice slice)\n    {\n        checkCondition(countCodePoints(slice) == 1, INVALID_FUNCTION_ARGUMENT, \"Input string must be a single character string\");\n\n        return getCodePointAt(slice, 0);\n    }\n\n    @Description(\"count of code points of the given string\")\n    @ScalarFunction\n    @LiteralParameters(\"x\")\n    @SqlType(StandardTypes.BIGINT)\n    public static long length(@SqlType(\"varchar(x)\") Slice slice)","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/StringFunctions.java#L57-L93","documentation":"chr(bigint) converts a Unicode code point into its UTF-8 single-character string. The value must be a valid Unicode code point; values outside the allowed ranges (negative, above 0x10FFFF, or the surrogate range 0xD800–0xDFFF) are rejected by SliceUtf8.codePointToUtf8 and rethrown as INVALID_FUNCTION_ARGUMENT.","triggerScenarios":"Calling chr(n) where n < 0, n > 0x10FFFF (1114111), or n is a surrogate code point (55296–57343); also implicitly via Ints.saturatedCast for huge BIGINT values, though saturation clamps those into the invalid negative/large range.","commonSituations":"Generating characters from byte values > 0x10FFFF, passing raw decimal data meant to be UTF-8 bytes rather than code points, off-by-one using 0x110000 as 'max + 1', generating surrogate halves of an emoji instead of the combined code point.","solutions":["Clamp or validate the argument to the range 0–1114111 before calling chr.","Skip the surrogate range 55296–57343 or use the actual combined code point for the character.","If you meant to decode bytes, use from_utf8(varbinary) instead of chr per byte."],"exampleFix":"// before\nSELECT chr(1114112); -- throws: not a valid Unicode code point\n// after\nSELECT chr(1114111); -- U+10FFFF, the maximum valid code point","handlingStrategy":"validation","validationCode":"-- guard clause before chr(n)\nWHERE n BETWEEN 0 AND 1114111 AND (n < 55296 OR n > 57343)","typeGuard":"// Java\nboolean isValidCodePoint(long n) {\n    return n >= 0 && n <= 0x10FFFF && !(n >= 0xD800 && n <= 0xDFFF);\n}","tryCatchPattern":null,"preventionTips":["Remember chr() takes code points, not UTF-8 byte values.","Never pass surrogate range values (55296-57343).","Cap arguments at 1114111 (0x10FFFF)."],"tags":["presto","unicode","string-functions","invalid-argument"],"backgroundTag":"invalid-unicode-code-point","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"}