apache/cassandra · error · InvalidTypeException
Cannot parse tuple value from
Error message
Cannot parse tuple value from "%s", at character %d expecting '(' but got '%c' What it means
The tuple codec's parse method expects CQL literal syntax, which must begin with '('. If the first non-space character of the input string is anything else, this InvalidTypeException is thrown with the offending character and its position. It is a string-literal parsing error, not a network or serialization issue.
Solutions
- Wrap the value in parentheses: parse("(1, 'abc')") instead of parse("1, 'abc'").
- Strip surrounding whitespace and validate the first non-space char is '(' before calling parse.
- If the data is already structured, build a TupleValue via TupleType.newValue(...) instead of parsing strings.
- Check for locale/formatting transformations that removed or replaced parentheses.
Example fix
// before
TupleValue v = tupleType.parse("1, 'abc'");
// after
TupleValue v = tupleType.parse("(1, 'abc')"); Defensive patterns
Strategy: validation
Validate before calling
String s = input.trim(); if (!s.startsWith("(")) throw new IllegalArgumentException("tuple literal must start with '(': " + s); Try / catch
try { return tupleType.parse(literal); } catch (InvalidTypeException e) { throw new IllegalArgumentException("malformed tuple literal: " + literal, e); } Prevention
- Validate CQL literals with a regex like \s*\(.*\)\s* before parsing
- Prefer typed construction (TupleType.newValue) over string parsing
- Trim input and normalize before parse
When it happens
Trigger: Calling TupleCodec.parse with input like "1, 'abc'" or "[1,'abc']" instead of "(1, 'abc')"; binding a user-entered tuple literal that lacks the opening parenthesis.
Common situations: Users typing tuple values in cqlsh or a form without parentheses; JSON-ish input fed to parse; copying values from logs that stripped the parens.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Cannot parse tuple value from
- Cannot parse tuple value from
- Malformed tuple value
- Cannot parse collection value from
- Cannot parse collection value from
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/80447c66f0e578e6.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2954
for (int i = 0; i < length; i++)
{
if (i > 0) sb.append(',');
sb.append(formatField(value, i));
}
sb.append(')');
return sb.toString();
}
@Override
public T parse(String value)
{
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null;
T v = newInstance();
int idx = ParseUtils.skipSpaces(value, 0);
if (value.charAt(idx++) != '(')
throw new InvalidTypeException(
String.format(
"Cannot parse tuple value from \"%s\", at character %d expecting '(' but got '%c'",
value, idx, value.charAt(idx)));
idx = ParseUtils.skipSpaces(value, idx);
if (value.charAt(idx) == ')') return v;
int i = 0;
while (idx < value.length())
{
int n;
try
{
n = ParseUtils.skipCQLValue(value, idx);
}
catch (IllegalArgumentException e)
{View on GitHub (pinned to 88fd0f6a0e)