gunicorn
gunicorn copied to clipboard
Display NameError on import
If user code raises a NameError when gunicorn is importing the application, the error will be swallowed. Gunicorn is catching NameError to handle the case where the entrypoint to the user app is not valid. However this also swallows other NameErrors in the user code, such as accessing an undefined variable. This PR makes the correct traceback available.
Thanks for the pull request! @berkerpeksag do you think it's okay to log tracebacks for this even when the app is not in debug? It seems alright to me, but would love a second opinion.
I had the same thought, if it's any help my reasoning was that it's not printing anything to stdout. Previously it would print the traceback to stdout if debug was enabled, and always raise an exception regardless of debug mode. This simply adds the traceback to the end of the exception message and altogether removes the printing. It's the same exception class being raised. I can't imagine having the additional information in the exception message would break anyone's code.
I think you can leave the error unchanged, since it's being raised. At least on Python 3 chained exceptions should make the original traceback available. We should change the self.log.debug
call In line 588 of arbiter.py to be an error level, though.
@berkerpeksag is there any better way to make sure the exception will be raised at debug level? Maybe just losing the exception there would be enough ?
I believe this is no longer needed since https://github.com/benoitc/gunicorn/pull/2043 - there is no longer any confusion between NameError from looking up the application and during import.