diff --git a/msgspec/_core.c b/msgspec/_core.c index bfb73680..83de473b 100644 --- a/msgspec/_core.c +++ b/msgspec/_core.c @@ -22102,7 +22102,7 @@ PyInit__core(void) st->DecodeError = PyErr_NewExceptionWithDoc( "msgspec.DecodeError", "An error occurred while decoding an object", - st->MsgspecError, NULL + PyTuple_Pack(2, st->MsgspecError, PyExc_ValueError), NULL ); if (st->DecodeError == NULL) return NULL; diff --git a/tests/test_common.py b/tests/test_common.py index 38898be3..2ca9f968 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -291,6 +291,14 @@ class Custom(metaclass=Metaclass): with pytest.raises(TypeError, match="Oh no!"): dec.decode(msg) + @pytest.mark.parametrize("err_cls", [msgspec.DecodeError, msgspec.ValidationError]) + def test_decode_errors_subclass_of_value_error(self, err_cls): + assert issubclass(err_cls, ValueError) + + @pytest.mark.parametrize("err_cls", [msgspec.EncodeError, msgspec.MsgspecError]) + def test_other_errors_not_subclass_of_value_error(self, err_cls): + assert not issubclass(err_cls, ValueError) + @pytest.mark.skipif( PY312,