@@ -1649,7 +1649,7 @@ static int write_raw_doc(buffer_t buffer, PyObject* raw, PyObject* _raw_str) {
1649
1649
*/
1650
1650
void handle_invalid_doc_error (PyObject * dict ) {
1651
1651
PyObject * etype = NULL , * evalue = NULL , * etrace = NULL ;
1652
- PyObject * msg = NULL , * dict_str = NULL , * new_msg = NULL ;
1652
+ PyObject * msg = NULL , * new_msg = NULL , * new_evalue = NULL ;
1653
1653
PyErr_Fetch (& etype , & evalue , & etrace );
1654
1654
PyObject * InvalidDocument = _error ("InvalidDocument" );
1655
1655
if (InvalidDocument == NULL ) {
@@ -1659,19 +1659,19 @@ void handle_invalid_doc_error(PyObject* dict) {
1659
1659
if (evalue && PyErr_GivenExceptionMatches (etype , InvalidDocument )) {
1660
1660
PyObject * msg = PyObject_Str (evalue );
1661
1661
if (msg ) {
1662
- // Add doc to the error class as a property.
1663
- PyObject_SetAttrString (InvalidDocument , "document" , dict );
1664
1662
const char * msg_utf8 = PyUnicode_AsUTF8 (msg );
1665
1663
if (msg_utf8 == NULL ) {
1666
1664
goto cleanup ;
1667
1665
}
1668
1666
PyObject * new_msg = PyUnicode_FromFormat ("Invalid document: %s" , msg_utf8 );
1667
+ // Add doc to the error instance as a property.
1668
+ PyObject * new_evalue = PyObject_CallFunctionObjArgs (InvalidDocument , new_msg , dict , NULL );
1669
1669
Py_DECREF (evalue );
1670
1670
Py_DECREF (etype );
1671
1671
etype = InvalidDocument ;
1672
1672
InvalidDocument = NULL ;
1673
- if (new_msg ) {
1674
- evalue = new_msg ;
1673
+ if (new_evalue ) {
1674
+ evalue = new_evalue ;
1675
1675
} else {
1676
1676
evalue = msg ;
1677
1677
}
@@ -1682,7 +1682,7 @@ void handle_invalid_doc_error(PyObject* dict) {
1682
1682
PyErr_Restore (etype , evalue , etrace );
1683
1683
Py_XDECREF (msg );
1684
1684
Py_XDECREF (InvalidDocument );
1685
- Py_XDECREF (dict_str );
1685
+ Py_XDECREF (new_evalue );
1686
1686
Py_XDECREF (new_msg );
1687
1687
}
1688
1688
0 commit comments