Skip to content

Commit

Permalink
Normalize JSONEncodeError.__cause__
Browse files Browse the repository at this point in the history
  • Loading branch information
ermakov-oleg authored and ijl committed Jul 7, 2023
1 parent 464d0b8 commit 4385666
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ fn raise_dumps_exception_dynamic(err: &String) -> *mut PyObject {
PyErr_NormalizeException(&mut tp, &mut val, &mut traceback);

if !cause_tp.is_null() {
PyErr_NormalizeException(&mut cause_tp, &mut cause_val, &mut cause_traceback);
PyException_SetCause(val, cause_val);
Py_DECREF(cause_tp);
}
Expand Down
6 changes: 6 additions & 0 deletions test/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,9 @@ def test_dumps_chain_default_customerror(self):
assert exc_info.type == orjson.JSONEncodeError
assert isinstance(exc_info.value.__cause__, CustomException)
assert str(exc_info.value.__cause__) == CUSTOM_ERROR_MESSAGE

def test_dumps_normalize_exception(self):
with pytest.raises(orjson.JSONEncodeError) as exc_info:
orjson.dumps(10**60)
assert exc_info.type == orjson.JSONEncodeError
assert isinstance(exc_info.value.__cause__, OverflowError)

0 comments on commit 4385666

Please sign in to comment.