Skip to content

Commit 29774d7

Browse files
committed
Assert before calling _set_debug_exception_cause
1 parent 173cde8 commit 29774d7

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

Modules/_remote_debugging/_remote_debugging.h

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,24 +173,13 @@ 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 - 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. */
179-
#define set_exception_cause(unwinder, exc_type, message) \
180-
do { \
181-
if (!PyErr_ExceptionMatches(PyExc_PermissionError)) { \
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 */ \
190-
PyErr_SetString(exc_type, message); \
191-
assert(PyErr_Occurred() && "function returned -1 without setting exception"); \
192-
} \
193-
} \
176+
/* Exception cause macro */
177+
#define set_exception_cause(unwinder, exc_type, message) \
178+
do { \
179+
assert(PyErr_Occurred() && "function returned -1 without setting exception"); \
180+
if (unwinder->debug) { \
181+
_set_debug_exception_cause(exc_type, message); \
182+
} \
194183
} while (0)
195184

196185
/* ============================================================================

0 commit comments

Comments
 (0)