Skip to content

Commit e0e5673

Browse files
committed
fix: include error message if possible in error
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 9b0dad5 commit e0e5673

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

include/pybind11/embed.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,14 @@ inline void initialize_interpreter(bool init_signal_handlers = true,
157157
// A failure here indicates a character-encoding failure or the python
158158
// interpreter out of memory. Give up.
159159
PyConfig_Clear(&config);
160-
throw std::runtime_error("Failed to prepare CPython");
160+
throw std::runtime_error(PyStatus_IsError(status) ? status.err_msg
161+
: "Failed to prepare CPython");
161162
}
162163
status = Py_InitializeFromConfig(&config);
163164
PyConfig_Clear(&config);
164165
if (PyStatus_Exception(status)) {
165-
throw std::runtime_error("Failed to init CPython");
166+
throw std::runtime_error(PyStatus_IsError(status) ? status.err_msg
167+
: "Failed to init CPython");
166168
}
167169
if (add_program_dir_to_path) {
168170
PyRun_SimpleString("import sys, os.path; "

0 commit comments

Comments
 (0)