Fix re-raising of KjException
- The `KjException._to_python()` function neglected to check if the wrapper was set when attempting to convert to `AttributeError`, leading to exceptions while raising an exception. - The syntax `raise A, B, C` hasn't existed since Python 3. The only reason it works is because Cython supports it. Lets get rid of it. - There was an attempt to convert a certain kind of `KjException` to an `AttributeError`. However, the original exception remains in the context when the new exception is raised. This is confusing. We get rid of the original exception by doing `raise e._to_python() from None`.
This commit is contained in:
committed by
Jacob Alexander
parent
ef5e039067
commit
49bda5ccae
@@ -260,9 +260,9 @@ class KjException(Exception):
|
|||||||
|
|
||||||
def _to_python(self):
|
def _to_python(self):
|
||||||
message = self.message
|
message = self.message
|
||||||
if self.wrapper.type == 'FAILED':
|
if self.wrapper is not None and self.wrapper.type == 'FAILED':
|
||||||
if 'has no such' in self.message:
|
if 'has no such' in self.message:
|
||||||
return AttributeError(message)
|
return AttributeError(message).with_traceback(self.__traceback__)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
@@ -1147,7 +1147,7 @@ cdef class _DynamicStructReader:
|
|||||||
try:
|
try:
|
||||||
return self._get(field)
|
return self._get(field)
|
||||||
except KjException as e:
|
except KjException as e:
|
||||||
raise e._to_python(), None, _sys.exc_info()[2]
|
raise e._to_python() from None
|
||||||
|
|
||||||
cpdef _get_by_field(self, _StructSchemaField field):
|
cpdef _get_by_field(self, _StructSchemaField field):
|
||||||
return to_python_reader(self.thisptr.getByField(field.thisptr), self)
|
return to_python_reader(self.thisptr.getByField(field.thisptr), self)
|
||||||
@@ -1394,7 +1394,7 @@ cdef class _DynamicStructBuilder:
|
|||||||
try:
|
try:
|
||||||
return self._get(field)
|
return self._get(field)
|
||||||
except KjException as e:
|
except KjException as e:
|
||||||
raise e._to_python(), None, _sys.exc_info()[2]
|
raise e._to_python() from None
|
||||||
|
|
||||||
cpdef _set(self, field, value):
|
cpdef _set(self, field, value):
|
||||||
_setDynamicField(self.thisptr, field, value, self._parent)
|
_setDynamicField(self.thisptr, field, value, self._parent)
|
||||||
@@ -1406,7 +1406,7 @@ cdef class _DynamicStructBuilder:
|
|||||||
try:
|
try:
|
||||||
self._set(field, value)
|
self._set(field, value)
|
||||||
except KjException as e:
|
except KjException as e:
|
||||||
raise e._to_python(), None, _sys.exc_info()[2]
|
raise e._to_python() from None
|
||||||
|
|
||||||
cpdef _has(self, field):
|
cpdef _has(self, field):
|
||||||
return self.thisptr.has(field)
|
return self.thisptr.has(field)
|
||||||
@@ -1658,7 +1658,7 @@ cdef class _DynamicStructPipeline:
|
|||||||
try:
|
try:
|
||||||
return self._get(field)
|
return self._get(field)
|
||||||
except KjException as e:
|
except KjException as e:
|
||||||
raise e._to_python(), None, _sys.exc_info()[2]
|
raise e._to_python() from None
|
||||||
|
|
||||||
property schema:
|
property schema:
|
||||||
"""A property that returns the _StructSchema object matching this reader"""
|
"""A property that returns the _StructSchema object matching this reader"""
|
||||||
@@ -2044,7 +2044,7 @@ cdef class _RemotePromise:
|
|||||||
try:
|
try:
|
||||||
return self._get(field)
|
return self._get(field)
|
||||||
except KjException as e:
|
except KjException as e:
|
||||||
raise e._to_python(), None, _sys.exc_info()[2]
|
raise e._to_python() from None
|
||||||
|
|
||||||
property schema:
|
property schema:
|
||||||
"""A property that returns the _StructSchema object matching this reader"""
|
"""A property that returns the _StructSchema object matching this reader"""
|
||||||
@@ -2198,7 +2198,7 @@ cdef class _DynamicCapabilityClient:
|
|||||||
raise AttributeError('Method named %s not found' % name)
|
raise AttributeError('Method named %s not found' % name)
|
||||||
return _partial(self._send, name)
|
return _partial(self._send, name)
|
||||||
except KjException as e:
|
except KjException as e:
|
||||||
raise e._to_python(), None, _sys.exc_info()[2]
|
raise e._to_python() from None
|
||||||
|
|
||||||
cpdef upcast(self, schema) except +reraise_kj_exception:
|
cpdef upcast(self, schema) except +reraise_kj_exception:
|
||||||
cdef _InterfaceSchema s
|
cdef _InterfaceSchema s
|
||||||
|
|||||||
Reference in New Issue
Block a user