Open jimgregory opened 6 years ago
can you make a PR so others can see the changes and maybe evaluate or comment on that?
cgitb is made for cgi scripts and won't work out of the box with bottle, because it only handles unhandled exceptions (those that would otherwise exit the interpreter loop). Bottle catches most exceptions to display the error page (and to be able to continue serving requests after an error) so the global error handler installed by cgitb would never be triggered.
The module is not very big, though. https://github.com/python/cpython/blob/3.6/Lib/cgitb.py It would be not that hard to write plugin with a custom error handler that provides a similar level of detail for the bottle error template.
The way I've implemented it seems to work. It seems to catch and display all the errors I've tested and continues to serve requests afterwards without having to restart the server.
But I may be misinterpreting what you've said, or not thinking of all possible error cases. I've submitted a PR and would appreciate your feedback. Thanks.
While I like bottle a lot, I've often had trouble debugging an application because the standard traceback does not provide much information in the stacktrace.
While t's possible to install a plugin (bottle_debugtoolbar) to help solve this problem, I've found it a bit bloated (it uses jinja templates, so it requires that module plus others) and buggy (I haven't always been able to get it to work in an existing app).
I recently came across cgitb, a module in the standard library of all current Python versions. It was originally designed to provide traceback information for cgi scripts, but can be used to debug any Python application.
The big advantage of this module is that it automatically displays:
This makes debugging much easier. So in a simple bottle app like this:
Rather than seeing this:
You get this (the original has better indentiation):
The required changes are minimal (two new lines of code, one deletion, and five changes). I can submit a pull request if there's interest.