mirror of
https://github.com/pybind/pybind11.git
synced 2024-12-02 01:47:12 +00:00
Replace extremely opaque (unhelpful) error message with a truthful reflection of what we know.
This commit is contained in:
parent
de84a27fd4
commit
498195ac4b
@ -473,8 +473,10 @@ PYBIND11_NOINLINE bool isinstance_generic(handle obj, const std::type_info &tp)
|
|||||||
PYBIND11_NOINLINE std::string
|
PYBIND11_NOINLINE std::string
|
||||||
error_string(PyObject *exc_type, PyObject *exc_value, PyObject *exc_trace) {
|
error_string(PyObject *exc_type, PyObject *exc_value, PyObject *exc_trace) {
|
||||||
if (!exc_type) {
|
if (!exc_type) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Unknown internal error occurred");
|
static const char *msg
|
||||||
return "Unknown internal error occurred";
|
= "Internal error: error_string() called without a Python error available.";
|
||||||
|
PyErr_SetString(PyExc_RuntimeError, msg);
|
||||||
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = handle(exc_type).attr("__name__").cast<std::string>();
|
auto result = handle(exc_type).attr("__name__").cast<std::string>();
|
||||||
|
@ -228,7 +228,10 @@ TEST_SUBMODULE(exceptions, m) {
|
|||||||
throw py::error_already_set();
|
throw py::error_already_set();
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
if ((err && e.what() != std::string("ValueError: foo"))
|
if ((err && e.what() != std::string("ValueError: foo"))
|
||||||
|| (!err && e.what() != std::string("Unknown internal error occurred"))) {
|
|| (!err
|
||||||
|
&& e.what()
|
||||||
|
!= std::string("Internal error: error_string() called without a Python "
|
||||||
|
"error available."))) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
throw std::runtime_error("error message mismatch");
|
throw std::runtime_error("error message mismatch");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user