Skip to content

Commit

Permalink
print caught exceptions when (de)serializing (#332)
Browse files Browse the repository at this point in the history
* print caught exceptions when (de)serializing

* include trace in error message

Co-authored-by: David Little <david.frank.little@gmail.com>

* print backtrace

* typo

* wrap sprint in try-catch block and print in debug

---------

Co-authored-by: David Little <david.frank.little@gmail.com>
  • Loading branch information
glennmoy and haberdashPI committed Jul 23, 2023
1 parent 5b90198 commit 7af2b30
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/cpython/jlwrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ function _pyjl_serialize(self::PyPtr, ::PyPtr)
return PyBytes_FromStringAndSize(pointer(b), sizeof(b))
catch e
PyErr_SetString(POINTERS.PyExc_Exception, "error serializing this value")
# wrap sprint in another try-catch block to prevent this function from throwing
try
@debug "Caught exception $(sprint(showerror, e, catch_backtrace()))"
catch e2
@debug "Error printing exception: $e2"
end
return PyNULL
end
end
Expand All @@ -221,6 +227,12 @@ function _pyjl_deserialize(t::PyPtr, v::PyPtr)
return PyJuliaValue_New(t, x)
catch e
PyErr_SetString(POINTERS.PyExc_Exception, "error deserializing this value")
# wrap sprint in another try-catch block to prevent this function from throwing
try
@debug "Caught exception $(sprint(showerror, e, catch_backtrace()))"
catch e2
@debug "Error printing exception: $e2"
end
return PyNULL
end
end
Expand Down

0 comments on commit 7af2b30

Please sign in to comment.