Skip to content

Commit

Permalink
pythongh-102056: Fix a few bugs in error handling of exception printi…
Browse files Browse the repository at this point in the history
…ng code
  • Loading branch information
iritkatriel committed Feb 20, 2023
1 parent 77d95c8 commit 2256302
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1246,8 +1246,7 @@ print_chained(struct exception_print_context* ctx, PyObject *value,
const char * message, const char *tag)
{
PyObject *f = ctx->file;

if (_Py_EnterRecursiveCall(" in print_chained") < 0) {
if (_Py_EnterRecursiveCall(" in print_chained") != 0) {
return -1;
}
bool need_close = ctx->need_close;
Expand Down Expand Up @@ -1374,7 +1373,9 @@ print_exception_group(struct exception_print_context *ctx, PyObject *value)
if (ctx->exception_group_depth == 0) {
ctx->exception_group_depth += 1;
}
print_exception(ctx, value);
if (print_exception(ctx, value) < 0) {
return -1;
}

PyObject *excs = ((PyBaseExceptionGroupObject *)value)->excs;
assert(excs && PyTuple_Check(excs));
Expand Down Expand Up @@ -1477,22 +1478,30 @@ print_exception_group(struct exception_print_context *ctx, PyObject *value)
static int
print_exception_recursive(struct exception_print_context *ctx, PyObject *value)
{
if (_Py_EnterRecursiveCall(" in print_exception_recursive") != 0) {
return -1;
}
if (ctx->seen != NULL) {
/* Exception chaining */
if (print_exception_cause_and_context(ctx, value) < 0) {
return -1;
goto error;
}
}
if (!_PyBaseExceptionGroup_Check(value)) {
if (print_exception(ctx, value) < 0) {
return -1;
goto error;
}
}
else if (print_exception_group(ctx, value) < 0) {
return -1;
goto error;
}
assert(!PyErr_Occurred());

_Py_LeaveRecursiveCall();
return 0;
error:
_Py_LeaveRecursiveCall();
return -1;
}

#define PyErr_MAX_GROUP_WIDTH 15
Expand Down

0 comments on commit 2256302

Please sign in to comment.