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

While parsing a tuple literal, after reading a field the codec expects either ')' (end) or ',' (next field). If the character at the current position is neither, this InvalidTypeException is thrown naming the position and the actual character. It indicates malformed CQL tuple literal syntax between fields.

Solutions

  1. Add the missing ',' between tuple fields: "(1, 'abc')".
  2. Use a string template/join over the fields so commas are generated programmatically.
  3. Parse fields yourself and construct the TupleValue via TupleType.newValue instead of literal parsing.
  4. Check the reported character index; the offending character shows what replaced the expected comma.

Example fix

// before
TupleValue v = tupleType.parse("(1 'abc')");
// after
TupleValue v = tupleType.parse("(1, 'abc')");
Defensive patterns

Strategy: validation

Validate before calling

if (!literal.matches("\\s*\\(\\s*.+(\\s*,\\s*.+)*\\s*\\)\\s*")) throw new IllegalArgumentException("fields must be comma-separated inside parens");

Try / catch

try { return tupleType.parse(lit); } catch (InvalidTypeException e) { throw new IllegalArgumentException("malformed tuple separator: " + lit, e); }

Prevention

When it happens

Trigger: Parsing "(1 'abc')" (missing comma), "(1: 'abc')" (wrong separator); extra spaces are fine but a semicolon or space separator instead of a comma triggers it.

Common situations: Hand-written literals in scripts or migrations with a missing comma between fields; templated CQL string building that dropped the comma; converting from JSON arrays [1,2] to tuple syntax incorrectly.

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


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/d94aaa69a01ba963. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2988

                }
                catch (IllegalArgumentException e)
                {
                    throw new InvalidTypeException(
                    String.format(
                    "Cannot parse tuple value from \"%s\", invalid CQL value at character %d",
                    value, idx),
                    e);
                }

                String input = value.substring(idx, n);
                v = parseAndSetField(input, v, i);
                idx = n;
                i += 1;

                idx = ParseUtils.skipSpaces(value, idx);
                if (value.charAt(idx) == ')') return v;
                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; // skip ','

                idx = ParseUtils.skipSpaces(value, idx);
            }
            throw new InvalidTypeException(
            String.format("Malformed tuple value \"%s\", missing closing ')'", value));
        }

        /**
         * Return a new instance of {@code T}.
         *
         * @return A new instance of {@code T}.
         */
        protected abstract T newInstance();

View on GitHub (pinned to 88fd0f6a0e)