prestodb/presto · error · PrestoException
INVALID_FUNCTION_ARGUMENT
INVALID_FUNCTION_ARGUMENT
Error message
Invalid color: '%s'
What it means
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.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/ColorFunctions.java:103
@ScalarFunction
@LiteralParameters("x")
@SqlType(ColorType.NAME)
public static long color(@SqlType("varchar(x)") Slice color)
{
int rgb = parseRgb(color);
if (rgb != -1) {
return rgb;
}
// encode system colors (0-15) as negative values, offset by one
try {
SystemColor systemColor = SystemColor.valueOf(upper(color).toStringUtf8());
int index = systemColor.getIndex();
return -(index + 1);
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid color: '%s'", color.toStringUtf8()), e);
}
}
@ScalarFunction
@SqlType(ColorType.NAME)
public static long rgb(@SqlType(StandardTypes.BIGINT) long red, @SqlType(StandardTypes.BIGINT) long green, @SqlType(StandardTypes.BIGINT) long blue)
{
checkCondition(red >= 0 && red <= 255, INVALID_FUNCTION_ARGUMENT, "red must be between 0 and 255");
checkCondition(green >= 0 && green <= 255, INVALID_FUNCTION_ARGUMENT, "green must be between 0 and 255");
checkCondition(blue >= 0 && blue <= 255, INVALID_FUNCTION_ARGUMENT, "blue must be between 0 and 255");
return (red << 16) | (green << 8) | blue;
}
/**
* Interpolate a color between lowColor and highColor based the provided value
* <p/>
* The value is truncated to the range [low, high] if it's outside.View on GitHub (pinned to 55bb57d202)
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
Example fix
// before SELECT COLOR(user_color) FROM t; -- user_color = 'chartreuse' // after SELECT rgb(154, 205, 50); -- or restrict user_color to supported names
Defensive patterns
Strategy: validation
Validate before calling
boolean ok = SUPPORTED_COLORS.contains(name.trim().toLowerCase());
Prevention
- Whitelist color names; use rgb() otherwise
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- GENERIC_INTERNAL_ERROR
- INVALID_FUNCTION_ARGUMENT
- INVALID_FUNCTION_ARGUMENT
- INVALID_FUNCTION_ARGUMENT
- NUMERIC_VALUE_OUT_OF_RANGE
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/0781cb8dfc23085c.
Report an issue: GitHub.