[New-bugs-announce] [issue41318] Better error message of "Cannot recover from stack overflow."

Heyi Tang report at bugs.python.org
Thu Jul 16 23:41:03 EDT 2020


New submission from Heyi Tang <tangheyi.09 at gmail.com>:

Is it possible to add more detailed message for the error "Cannot recover from stack overflow"?
Something like "Cannot recover from stack overflow, it may be caused by catching a RecursionError but reaching the limit again before properly handling it."
Maybe the detailed design in https://github.com/python/cpython/blob/master/Include/ceval.h#L48 could also be shown to the developer?

It is hard to understand what happened only with the message "Cannot recover from stack overflow".

I hit the error because I write the code as following:
@some_logger
def f():
    return f()
try:
  f()
except RecursionError:
  print("Recursion Error is raised!")

And it took me a lot of time to figure out why RecursionError is not raised but the "Fatal Python error" is shown.
Finally I realized that the problem is that the following code piece in "some_logger" (Which is an internal library provided by others) caught the exception and make tstate->overflowed=1.

def some_logger(func):
    @functools.wraps(func)
    def new_func(*args, **kwargs):
        try:
            # Unfortunately this code hit RecursionError and catched it
            logger.info(some_message)
        except Exception as e:
            pass # Avoid affecting user function
        return func(*args, **kwargs)
    return new_func

So I think it might be better to provide more information to the developer that "Cannot recover" means that "RecursionError is caught and stack overflow again." and hint user to know the design of _Py_EnterRecursiveCall.

----------
components: Interpreter Core
messages: 373796
nosy: thyyyy
priority: normal
severity: normal
status: open
title: Better error message of "Cannot recover from stack overflow."
type: enhancement
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41318>
_______________________________________


More information about the New-bugs-announce mailing list