Skip to content

Commit 7af2b30

Browse files
print caught exceptions when (de)serializing (#332)
* print caught exceptions when (de)serializing * include trace in error message Co-authored-by: David Little <[email protected]> * print backtrace * typo * wrap sprint in try-catch block and print in debug --------- Co-authored-by: David Little <[email protected]>
1 parent 5b90198 commit 7af2b30

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/cpython/jlwrap.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ function _pyjl_serialize(self::PyPtr, ::PyPtr)
206206
return PyBytes_FromStringAndSize(pointer(b), sizeof(b))
207207
catch e
208208
PyErr_SetString(POINTERS.PyExc_Exception, "error serializing this value")
209+
# wrap sprint in another try-catch block to prevent this function from throwing
210+
try
211+
@debug "Caught exception $(sprint(showerror, e, catch_backtrace()))"
212+
catch e2
213+
@debug "Error printing exception: $e2"
214+
end
209215
return PyNULL
210216
end
211217
end
@@ -221,6 +227,12 @@ function _pyjl_deserialize(t::PyPtr, v::PyPtr)
221227
return PyJuliaValue_New(t, x)
222228
catch e
223229
PyErr_SetString(POINTERS.PyExc_Exception, "error deserializing this value")
230+
# wrap sprint in another try-catch block to prevent this function from throwing
231+
try
232+
@debug "Caught exception $(sprint(showerror, e, catch_backtrace()))"
233+
catch e2
234+
@debug "Error printing exception: $e2"
235+
end
224236
return PyNULL
225237
end
226238
end

0 commit comments

Comments
 (0)