Skip to content

Commit 2256302

Browse files
committed
pythongh-102056: Fix a few bugs in error handling of exception printing code
1 parent 77d95c8 commit 2256302

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Python/pythonrun.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,8 +1246,7 @@ print_chained(struct exception_print_context* ctx, PyObject *value,
12461246
const char * message, const char *tag)
12471247
{
12481248
PyObject *f = ctx->file;
1249-
1250-
if (_Py_EnterRecursiveCall(" in print_chained") < 0) {
1249+
if (_Py_EnterRecursiveCall(" in print_chained") != 0) {
12511250
return -1;
12521251
}
12531252
bool need_close = ctx->need_close;
@@ -1374,7 +1373,9 @@ print_exception_group(struct exception_print_context *ctx, PyObject *value)
13741373
if (ctx->exception_group_depth == 0) {
13751374
ctx->exception_group_depth += 1;
13761375
}
1377-
print_exception(ctx, value);
1376+
if (print_exception(ctx, value) < 0) {
1377+
return -1;
1378+
}
13781379

13791380
PyObject *excs = ((PyBaseExceptionGroupObject *)value)->excs;
13801381
assert(excs && PyTuple_Check(excs));
@@ -1477,22 +1478,30 @@ print_exception_group(struct exception_print_context *ctx, PyObject *value)
14771478
static int
14781479
print_exception_recursive(struct exception_print_context *ctx, PyObject *value)
14791480
{
1481+
if (_Py_EnterRecursiveCall(" in print_exception_recursive") != 0) {
1482+
return -1;
1483+
}
14801484
if (ctx->seen != NULL) {
14811485
/* Exception chaining */
14821486
if (print_exception_cause_and_context(ctx, value) < 0) {
1483-
return -1;
1487+
goto error;
14841488
}
14851489
}
14861490
if (!_PyBaseExceptionGroup_Check(value)) {
14871491
if (print_exception(ctx, value) < 0) {
1488-
return -1;
1492+
goto error;
14891493
}
14901494
}
14911495
else if (print_exception_group(ctx, value) < 0) {
1492-
return -1;
1496+
goto error;
14931497
}
14941498
assert(!PyErr_Occurred());
1499+
1500+
_Py_LeaveRecursiveCall();
14951501
return 0;
1502+
error:
1503+
_Py_LeaveRecursiveCall();
1504+
return -1;
14961505
}
14971506

14981507
#define PyErr_MAX_GROUP_WIDTH 15

0 commit comments

Comments
 (0)