From f5f7d280d65e928f674fb3c6ceb418007b4f3ec3 Mon Sep 17 00:00:00 2001 From: Glenn Moynihan Date: Wed, 28 Jun 2023 17:48:48 +0000 Subject: [PATCH 1/5] print caught exceptions when (de)serializing --- src/cpython/jlwrap.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cpython/jlwrap.jl b/src/cpython/jlwrap.jl index cce75270..6671282b 100644 --- a/src/cpython/jlwrap.jl +++ b/src/cpython/jlwrap.jl @@ -205,7 +205,10 @@ function _pyjl_serialize(self::PyPtr, ::PyPtr) b = take!(io) return PyBytes_FromStringAndSize(pointer(b), sizeof(b)) catch e - PyErr_SetString(POINTERS.PyExc_Exception, "error serializing this value") + PyErr_SetString( + POINTERS.PyExc_Exception, + "error serializing this value. Caught exception $e" + ) return PyNULL end end @@ -220,7 +223,10 @@ function _pyjl_deserialize(t::PyPtr, v::PyPtr) x = deserialize(io) return PyJuliaValue_New(t, x) catch e - PyErr_SetString(POINTERS.PyExc_Exception, "error deserializing this value") + PyErr_SetString( + POINTERS.PyExc_Exception, + "error deserializing this value. Caught exception $e" + ) return PyNULL end end From c541b3bff26627b04f0e08eb0bd5945ecf9238bf Mon Sep 17 00:00:00 2001 From: Glenn Moynihan Date: Wed, 28 Jun 2023 22:17:55 +0100 Subject: [PATCH 2/5] include trace in error message Co-authored-by: David Little --- src/cpython/jlwrap.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpython/jlwrap.jl b/src/cpython/jlwrap.jl index 6671282b..c85b0405 100644 --- a/src/cpython/jlwrap.jl +++ b/src/cpython/jlwrap.jl @@ -225,7 +225,7 @@ function _pyjl_deserialize(t::PyPtr, v::PyPtr) catch e PyErr_SetString( POINTERS.PyExc_Exception, - "error deserializing this value. Caught exception $e" + "error deserializing this value. Caught exception $(sprint(showerror, e. catch_backtrace()))" ) return PyNULL end From b39e415ecca62070b1fc1122ce869d9e82e46748 Mon Sep 17 00:00:00 2001 From: Glenn Moynihan Date: Thu, 29 Jun 2023 08:51:15 +0100 Subject: [PATCH 3/5] print backtrace --- src/cpython/jlwrap.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpython/jlwrap.jl b/src/cpython/jlwrap.jl index c85b0405..559bd98e 100644 --- a/src/cpython/jlwrap.jl +++ b/src/cpython/jlwrap.jl @@ -207,7 +207,7 @@ function _pyjl_serialize(self::PyPtr, ::PyPtr) catch e PyErr_SetString( POINTERS.PyExc_Exception, - "error serializing this value. Caught exception $e" + "error serializing this value. Caught exception $(sprint(showerror, e. catch_backtrace()))" ) return PyNULL end From 83a21bb66d0a89c8f8620d81dcf1ff91bb3c2f35 Mon Sep 17 00:00:00 2001 From: Glenn Moynihan Date: Thu, 29 Jun 2023 13:49:46 +0100 Subject: [PATCH 4/5] typo --- src/cpython/jlwrap.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpython/jlwrap.jl b/src/cpython/jlwrap.jl index 559bd98e..9a405546 100644 --- a/src/cpython/jlwrap.jl +++ b/src/cpython/jlwrap.jl @@ -207,7 +207,7 @@ function _pyjl_serialize(self::PyPtr, ::PyPtr) catch e PyErr_SetString( POINTERS.PyExc_Exception, - "error serializing this value. Caught exception $(sprint(showerror, e. catch_backtrace()))" + "error serializing this value. Caught exception $(sprint(showerror, e, catch_backtrace()))" ) return PyNULL end @@ -225,7 +225,7 @@ function _pyjl_deserialize(t::PyPtr, v::PyPtr) catch e PyErr_SetString( POINTERS.PyExc_Exception, - "error deserializing this value. Caught exception $(sprint(showerror, e. catch_backtrace()))" + "error deserializing this value. Caught exception $(sprint(showerror, e, catch_backtrace()))" ) return PyNULL end From a0f461d6b6643b3b7ecc49e1df6593ea9ba01c48 Mon Sep 17 00:00:00 2001 From: Glenn Moynihan Date: Wed, 5 Jul 2023 15:22:41 +0100 Subject: [PATCH 5/5] wrap sprint in try-catch block and print in debug --- src/cpython/jlwrap.jl | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/cpython/jlwrap.jl b/src/cpython/jlwrap.jl index 9a405546..2738a4f2 100644 --- a/src/cpython/jlwrap.jl +++ b/src/cpython/jlwrap.jl @@ -205,10 +205,13 @@ function _pyjl_serialize(self::PyPtr, ::PyPtr) b = take!(io) return PyBytes_FromStringAndSize(pointer(b), sizeof(b)) catch e - PyErr_SetString( - POINTERS.PyExc_Exception, - "error serializing this value. Caught exception $(sprint(showerror, e, catch_backtrace()))" - ) + 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 @@ -223,10 +226,13 @@ function _pyjl_deserialize(t::PyPtr, v::PyPtr) x = deserialize(io) return PyJuliaValue_New(t, x) catch e - PyErr_SetString( - POINTERS.PyExc_Exception, - "error deserializing this value. Caught exception $(sprint(showerror, e, catch_backtrace()))" - ) + 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