@@ -1645,11 +1645,11 @@ static int write_raw_doc(buffer_t buffer, PyObject* raw, PyObject* _raw_str) {
1645
1645
}
1646
1646
1647
1647
1648
- /* Update Invalid Document error message to include doc.
1648
+ /* Update Invalid Document error to include doc as a property .
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,26 +1659,22 @@ 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
- // Prepend doc to the existing message
1663
- PyObject * dict_str = PyObject_Str (dict );
1664
- if (dict_str == NULL ) {
1665
- goto cleanup ;
1666
- }
1667
- const char * dict_str_utf8 = PyUnicode_AsUTF8 (dict_str );
1668
- if (dict_str_utf8 == NULL ) {
1669
- goto cleanup ;
1670
- }
1671
1662
const char * msg_utf8 = PyUnicode_AsUTF8 (msg );
1672
1663
if (msg_utf8 == NULL ) {
1673
1664
goto cleanup ;
1674
1665
}
1675
- PyObject * new_msg = PyUnicode_FromFormat ("Invalid document %s | %s" , dict_str_utf8 , msg_utf8 );
1666
+ PyObject * new_msg = PyUnicode_FromFormat ("Invalid document: %s" , msg_utf8 );
1667
+ if (new_msg == NULL ) {
1668
+ goto cleanup ;
1669
+ }
1670
+ // Add doc to the error instance as a property.
1671
+ PyObject * new_evalue = PyObject_CallFunctionObjArgs (InvalidDocument , new_msg , dict , NULL );
1676
1672
Py_DECREF (evalue );
1677
1673
Py_DECREF (etype );
1678
1674
etype = InvalidDocument ;
1679
1675
InvalidDocument = NULL ;
1680
- if (new_msg ) {
1681
- evalue = new_msg ;
1676
+ if (new_evalue ) {
1677
+ evalue = new_evalue ;
1682
1678
} else {
1683
1679
evalue = msg ;
1684
1680
}
@@ -1689,7 +1685,7 @@ void handle_invalid_doc_error(PyObject* dict) {
1689
1685
PyErr_Restore (etype , evalue , etrace );
1690
1686
Py_XDECREF (msg );
1691
1687
Py_XDECREF (InvalidDocument );
1692
- Py_XDECREF (dict_str );
1688
+ Py_XDECREF (new_evalue );
1693
1689
Py_XDECREF (new_msg );
1694
1690
}
1695
1691
0 commit comments