consistent error message on deserialization failure
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
include "ioutils.pyx"
|
include "ioutils.pyx"
|
||||||
|
|
||||||
|
from cassandra import DriverException
|
||||||
from cassandra.bytesio cimport BytesIOReader
|
from cassandra.bytesio cimport BytesIOReader
|
||||||
from cassandra.deserializers cimport Deserializer, from_binary
|
from cassandra.deserializers cimport Deserializer, from_binary
|
||||||
from cassandra.parsing cimport ParseDesc, ColumnParser, RowParser
|
from cassandra.parsing cimport ParseDesc, ColumnParser, RowParser
|
||||||
@@ -67,8 +68,12 @@ cdef class TupleRowParser(RowParser):
|
|||||||
|
|
||||||
# Deserialize bytes to python object
|
# Deserialize bytes to python object
|
||||||
deserializer = desc.deserializers[i]
|
deserializer = desc.deserializers[i]
|
||||||
val = from_binary(deserializer, &buf, desc.protocol_version)
|
try:
|
||||||
|
val = from_binary(deserializer, &buf, desc.protocol_version)
|
||||||
|
except Exception as e:
|
||||||
|
raise DriverException('Failed decoding result column "%s" of type %s: %s' % (desc.colnames[i],
|
||||||
|
desc.coltypes[i].cql_parameterized_type(),
|
||||||
|
str(e)))
|
||||||
# Insert new object into tuple
|
# Insert new object into tuple
|
||||||
tuple_set(res, i, val)
|
tuple_set(res, i, val)
|
||||||
|
|
||||||
|
|||||||
@@ -651,7 +651,7 @@ class ResultMessage(_MessageType):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise DriverException('Failed decoding result column "%s" of type %s: %s' % (colnames[i],
|
raise DriverException('Failed decoding result column "%s" of type %s: %s' % (colnames[i],
|
||||||
coltypes[i].cql_parameterized_type(),
|
coltypes[i].cql_parameterized_type(),
|
||||||
e.message))
|
str(e)))
|
||||||
return paging_state, coltypes, (colnames, parsed_rows)
|
return paging_state, coltypes, (colnames, parsed_rows)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from cassandra.parsing cimport ParseDesc, ColumnParser
|
from cassandra.parsing cimport ParseDesc, ColumnParser
|
||||||
|
from cassandra.obj_parser import TupleRowParser
|
||||||
from cassandra.deserializers import make_deserializers
|
from cassandra.deserializers import make_deserializers
|
||||||
|
|
||||||
include "ioutils.pyx"
|
include "ioutils.pyx"
|
||||||
@@ -33,7 +34,16 @@ def make_recv_results_rows(ColumnParser colparser):
|
|||||||
desc = ParseDesc(colnames, coltypes, make_deserializers(coltypes),
|
desc = ParseDesc(colnames, coltypes, make_deserializers(coltypes),
|
||||||
protocol_version)
|
protocol_version)
|
||||||
reader = BytesIOReader(f.read())
|
reader = BytesIOReader(f.read())
|
||||||
parsed_rows = colparser.parse_rows(reader, desc)
|
try:
|
||||||
|
parsed_rows = colparser.parse_rows(reader, desc)
|
||||||
|
except Exception as e:
|
||||||
|
# Use explicitly the TupleRowParser to display better error messages for column decoding failures
|
||||||
|
rowparser = TupleRowParser()
|
||||||
|
reader.buf_ptr = reader.buf
|
||||||
|
reader.pos = 0
|
||||||
|
rowcount = read_int(reader)
|
||||||
|
for i in range(rowcount):
|
||||||
|
rowparser.unpack_row(reader, desc)
|
||||||
|
|
||||||
return (paging_state, coltypes, (colnames, parsed_rows))
|
return (paging_state, coltypes, (colnames, parsed_rows))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user