Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 380c3d1

Browse files
committedJul 5, 2022
fix: include error message if possible in error
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 9b0dad5 commit 380c3d1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed
 

‎include/pybind11/embed.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ 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.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.err_msg : "Failed to init CPython");
166167
}
167168
if (add_program_dir_to_path) {
168169
PyRun_SimpleString("import sys, os.path; "

0 commit comments

Comments
 (0)
Please sign in to comment.