{"record":{"id":"0781cb8dfc23085c","repo":"prestodb/presto","slug":"invalid-function-argument-0781cb","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Invalid color: '%s'","messagePattern":"Invalid color: '(.+?)'","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/ColorFunctions.java","lineNumber":103,"sourceCode":"    @ScalarFunction\n    @LiteralParameters(\"x\")\n    @SqlType(ColorType.NAME)\n    public static long color(@SqlType(\"varchar(x)\") Slice color)\n    {\n        int rgb = parseRgb(color);\n\n        if (rgb != -1) {\n            return rgb;\n        }\n\n        // encode system colors (0-15) as negative values, offset by one\n        try {\n            SystemColor systemColor = SystemColor.valueOf(upper(color).toStringUtf8());\n            int index = systemColor.getIndex();\n            return -(index + 1);\n        }\n        catch (IllegalArgumentException e) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format(\"Invalid color: '%s'\", color.toStringUtf8()), e);\n        }\n    }\n\n    @ScalarFunction\n    @SqlType(ColorType.NAME)\n    public static long rgb(@SqlType(StandardTypes.BIGINT) long red, @SqlType(StandardTypes.BIGINT) long green, @SqlType(StandardTypes.BIGINT) long blue)\n    {\n        checkCondition(red >= 0 && red <= 255, INVALID_FUNCTION_ARGUMENT, \"red must be between 0 and 255\");\n        checkCondition(green >= 0 && green <= 255, INVALID_FUNCTION_ARGUMENT, \"green must be between 0 and 255\");\n        checkCondition(blue >= 0 && blue <= 255, INVALID_FUNCTION_ARGUMENT, \"blue must be between 0 and 255\");\n\n        return (red << 16) | (green << 8) | blue;\n    }\n\n    /**\n     * Interpolate a color between lowColor and highColor based the provided value\n     * <p/>\n     * The value is truncated to the range [low, high] if it's outside.","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/ColorFunctions.java#L85-L121","documentation":"color(varchar) looks up a color by name (case-insensitively) against the predefined system-color set. If the name is not recognized, the underlying IllegalArgumentException is rethrown as INVALID_FUNCTION_ARGUMENT with the offending name included.","triggerScenarios":"Calling COLOR('name') with a name outside the system color list, e.g. COLOR('chartreuse'), empty string, or a value with unexpected casing/whitespace from user data.","commonSituations":"Assuming CSS color names are supported (only the Java SystemColor set is); names read from config files or user input with typos or trailing spaces.","solutions":["Use one of the supported system color names (e.g. 'red', 'black', 'blue')","Use the rgb(r,g,b) function to construct arbitrary colors instead of names","Normalize input: TRIM/UPPER the value and validate against the known list before calling"],"exampleFix":"// before\nSELECT COLOR(user_color) FROM t; -- user_color = 'chartreuse'\n// after\nSELECT rgb(154, 205, 50); -- or restrict user_color to supported names\n","handlingStrategy":"validation","validationCode":"boolean ok = SUPPORTED_COLORS.contains(name.trim().toLowerCase());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Whitelist color names; use rgb() otherwise"],"tags":["sql","scalar-function","invalid-argument","color"],"backgroundTag":"invalid-color-name","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"}