prestodb/presto · error · IllegalArgumentException
Could not parse selected role:
Error message
Could not parse selected role:
What it means
SelectedRole.valueOf parses the string form '<TYPE> <role>' (e.g. 'ROLE admin', 'NONE') using a regex PATTERN and throws IllegalArgumentException 'Could not parse selected role: <value>' when the string does not match. It is used to round-trip the toString representation back into a SelectedRole.
Source
Thrown at presto-spi/src/main/java/com/facebook/presto/spi/security/SelectedRole.java:120
@Override
public String toString()
{
StringBuilder result = new StringBuilder();
result.append(type);
role.ifPresent(s -> result.append("{").append(s).append("}"));
return result.toString();
}
public static SelectedRole valueOf(String value)
{
Matcher m = PATTERN.matcher(value);
if (m.matches()) {
Type type = Type.valueOf(m.group(1));
Optional<String> role = Optional.ofNullable(m.group(3));
return new SelectedRole(type, role);
}
throw new IllegalArgumentException("Could not parse selected role: " + value);
}
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Check the exact expected format in SelectedRole.toString and correct the input (e.g. 'ROLE admin')
- Use SelectedRole(Type, Optional) construction directly instead of parsing ad-hoc strings
- Handle legacy formats by normalizing separators/type names before calling valueOf
- Wrap in try/catch and fall back to SelectedRole(Type.NONE, Optional.empty()) for unparseable legacy values
Example fix
// before
SelectedRole.valueOf("role=admin"); // throws
// after
SelectedRole.valueOf("ROLE admin");
// or safer:
try { sr = SelectedRole.valueOf(raw); } catch (IllegalArgumentException e) { sr = new SelectedRole(SelectedRole.Type.NONE, Optional.empty()); } Defensive patterns
Strategy: type-guard
Validate before calling
// validate format before parsing
if (!value.matches("(NONE|ALL|ROLE)( \\S+)?$")) {
throw new IllegalArgumentException("Bad SelectedRole string: " + value);
} Type guard
Optional<SelectedRole> tryParseSelectedRole(String value) {
try {
return Optional.of(SelectedRole.valueOf(value));
} catch (IllegalArgumentException e) {
return Optional.empty();
}
} Try / catch
try {
return SelectedRole.valueOf(value);
} catch (IllegalArgumentException e) {
LOG.warn("Could not parse selected role '%s'; defaulting to NONE", value);
return new SelectedRole(SelectedRole.Type.NONE, Optional.empty());
} Prevention
- Persist SelectedRole via its canonical toString output only
- Add a parser round-trip test: valueOf(toString()) for all types
- Normalize legacy formats before parsing
- Never hand-edit stored role strings without validating the format
When it happens
Trigger: Calling SelectedRole.valueOf on a string not matching the PATTERN regex — e.g. missing type, unknown type name, wrong separator, empty string, or a value produced by a different/older serialization format.
Common situations: Internal tools storing SelectedRole strings in config/DB across Presto version upgrades where the format changed; manually typed values in properties files; interop with clients that serialize roles differently (e.g. 'ROLE:admin' instead of 'ROLE admin').
Related errors
- QualifiedObjectName should have exactly 3 parts, found %s: %
- Bad type signature: '%s'
- INVALID_FUNCTION_ARGUMENT
- Invalid day-time interval:
- Invalid year-month interval:
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/53e5a391e82486a4.
Report an issue: GitHub.