File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Modules/_remote_debugging Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -173,14 +173,22 @@ typedef enum _WIN32_THREADSTATE {
173173#define THREAD_STATUS_GIL_REQUESTED (1 << 3)
174174#define THREAD_STATUS_HAS_EXCEPTION (1 << 4)
175175
176- /* Exception cause macro */
176+ /* Exception cause macro - chains context to existing exceptions in debug mode.
177+ * This macro assumes an exception has already been set by the failing function.
178+ * If no exception exists, this indicates a bug that should be fixed. */
177179#define set_exception_cause (unwinder , exc_type , message ) \
178180 do { \
179181 if (!PyErr_ExceptionMatches(PyExc_PermissionError)) { \
180- if (!PyErr_Occurred()) { \
182+ if (PyErr_Occurred()) { \
183+ if (unwinder->debug) { \
184+ /* Chain exception with context */ \
185+ _PyErr_FormatFromCause (exc_type , "%s" , message ); \
186+ } \
187+ } else { \
188+ /* BUG: Exception should have been set by caller */ \
189+ /* Fallback prevents crash; assert catches bug in debug builds */ \
181190 PyErr_SetString (exc_type , message ); \
182- } else if (unwinder->debug) { \
183- _PyErr_FormatFromCause(exc_type, "%s", message); \
191+ assert (PyErr_Occurred () && "function returned -1 without setting exception" ); \
184192 } \
185193 } \
186194 } while (0 )
You can’t perform that action at this time.
0 commit comments