apache/cassandra · error · InvalidRequestException
Invalid limit value
Error message
Invalid limit value
What it means
SelectStatement builds the effective LIMIT from the bound variables; when a LIMIT provided via a bind marker fails to unmarshal as an Int32 (Int32Type.validate throws MarshalException), it is rejected with InvalidRequestException 'Invalid limit value'. It means the byte payload bound to the LIMIT variable is not a valid 4-byte int, or (in programmatic use) the value's serialization is malformed.
Solutions
- Bind LIMIT ? as a proper int32 value using the driver's int type
- Do not pass the limit as a string; convert client-side before binding
- If writing raw bytes, ensure exactly 4 bytes big-endian signed int > 0
- Alternatively inline a literal LIMIT n instead of a bind marker
Example fix
// before
stmt.bind("10"); // LIMIT ? bound as string
// after
stmt.bind(10); // bind as int Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof limit !== 'number' || !Number.isInteger(limit) || limit <= 0) throw new Error('LIMIT must be a positive integer before binding'); Type guard
function isValidLimit(v) { return Number.isInteger(v) && v > 0 && v <= 2147483647; } Try / catch
try { session.execute(stmt, params); } catch (e) { if (e.message === 'Invalid limit value') coerceLimitParamToInt(params); else throw e; } Prevention
- Bind LIMIT placeholders with the driver's int type, never strings or raw buffers
- Validate limit values are positive 32-bit ints at the API boundary
- Prefer literal LIMIT n when the value is known at query-build time
When it happens
Trigger: Binding a driver value of the wrong type/format to the LIMIT ? placeholder (e.g. a string '10', a long/short with wrong encoding, or raw bytes that are not 4-byte big-endian ints) in a prepared statement.
Common situations: Low-level clients or custom drivers binding raw byte buffers for LIMIT; ORM/tooling that interpolates LIMIT as a string; ported code that previously used string limits.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Cannot assign value to of type
- Cannot assign value to of type
- Cannot cast value to type
- Cannot replace aggregate
- Cannot replace function
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/99e94555bc46e309.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/statements/SelectStatement.java:1055
private int getLimit(Term limit, QueryOptions options)
{
int userLimit = DataLimits.NO_LIMIT;
if (limit != null)
{
ByteBuffer b = checkNotNull(limit.bindAndGet(options), "Invalid null value of limit");
// treat UNSET limit value as 'unlimited'
if (b != UNSET_BYTE_BUFFER)
{
try
{
Int32Type.instance.validate(b);
userLimit = Int32Type.instance.compose(b);
checkTrue(userLimit > 0, "LIMIT must be strictly positive");
}
catch (MarshalException e)
{
throw new InvalidRequestException("Invalid limit value");
}
}
}
return userLimit;
}
private NavigableSet<Clustering<?>> getRequestedRows(QueryOptions options, ClientState state) throws InvalidRequestException
{
// Note: getRequestedColumns don't handle static columns, but due to CASSANDRA-5762
// we always do a slice for CQL3 tables, so it's ok to ignore them here
assert !restrictions.isColumnRange();
return restrictions.getClusteringColumns(options, state);
}
/**
* May be used by custom QueryHandler implementations
*/
public RowFilter getRowFilter(QueryOptions options, ClientState state) throws InvalidRequestExceptionView on GitHub (pinned to 88fd0f6a0e)