Hao Zhong created CASSANDRA-18484:
-------------------------------------
Summary: FunctionCall can throw more specific exceptions
Key: CASSANDRA-18484
URL: https://issues.apache.org/jira/browse/CASSANDRA-18484
Project: Cassandra
Issue Type: Bug
Reporter: Hao Zhong
FunctionCall has the following code:
{code:java}
private static ByteBuffer executeInternal(ProtocolVersion protocolVersion,
ScalarFunction fun, List<ByteBuffer> params) throws InvalidRequestException
{
ByteBuffer result = fun.execute(protocolVersion, params);
try
{
// Check the method didn't lied on it's declared return type
if (result != null)
fun.returnType().validate(result);
return result;
}
catch (MarshalException e)
{
throw new RuntimeException(String.format("Return of function %s
(%s) is not a valid value for its declared return type %s",
fun,
ByteBufferUtil.bytesToHex(result), fun.returnType().asCQL3Type()), e);
}
}
{code}
When validate throws MarshalException, it rethrows RuntimeException. Other
methods throw more specific exceptions. For example, BytesConversionFcts throws
{color:#000000}InvalidRequestException:{color}
{code:java}
public ByteBuffer execute(ProtocolVersion protocolVersion, List<ByteBuffer>
parameters)
{
ByteBuffer val = parameters.get(0);
if (val != null)
{
try
{
toType.getType().validate(val);
}
catch (MarshalException e)
{
throw new InvalidRequestException(String.format("In call to
function %s, value 0x%s is not a " +
"valid
binary representation for type %s",
name,
ByteBufferUtil.bytesToHex(val), toType));
}
}
return val;
}
{code}
{color:#000000}{color:#000000}As another example, Validation also rethrows this
exception:{color}{color}
{code:java}
public static void validateKey(TableMetadata metadata, ByteBuffer key)
{
...
try
{
metadata.partitionKeyType.validate(key);
}
catch (MarshalException e)
{
throw new InvalidRequestException(e.getMessage());
}
}
{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]