From f796498aaaaf2bc110efd494d4036d48999b1a61 Mon Sep 17 00:00:00 2001 From: Braedon Vickers Date: Fri, 17 Apr 2020 19:42:23 +0800 Subject: Don't re-raise critical errors that occur while handling an error This logic was added to satisfy pep-3333, where the error handling section says application authors should "never trap errors raised by start_response when exc_info is being provided". However, this appears to be intended to prevent applications from catching exc_info being re-raised by start_response(), which happens when an application tries to send an error response (includes exc_info), but can't as output has already been written to the client. These exceptions should be thrown up to the server so it can abort the connection, not caught by the application. In this case, the start_response() call in question may be an error response, but it's always the first call to start_response(), so should never re-raise exc_info in this way. As such, the special handling is unnecessary. --- bottle.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/bottle.py b/bottle.py index 68f2253..3c18ae9 100755 --- a/bottle.py +++ b/bottle.py @@ -1106,7 +1106,6 @@ class Bottle(object): def wsgi(self, environ, start_response): """ The bottle WSGI-interface. """ - provided_exc_info = False try: out = self._cast(self._handle(environ)) # rfc2616 section 4.3 @@ -1117,13 +1116,11 @@ class Bottle(object): exc_info = environ.get('bottle.exc_info') if exc_info is not None: del environ['bottle.exc_info'] - provided_exc_info = True start_response(response._wsgi_status_line(), response.headerlist, exc_info) return out except (KeyboardInterrupt, SystemExit, MemoryError): raise except Exception as E: - if provided_exc_info: raise if not self.catchall: raise err = '

Critical error while processing request: %s

' \ % html_escape(environ.get('PATH_INFO', '/')) -- cgit v1.2.1