From 1a413a8ffe1a9be4e94c78cfe111a90e4e232a4c Mon Sep 17 00:00:00 2001 From: latifbaihaki Date: Mon, 22 Dec 2025 08:27:48 +0800 Subject: [PATCH] Improve exception handler in wsgi_app method Replace bare except clause with explicit BaseException handler for better code clarity and to avoid potential issues with sys.exc_info(). The previous code used a bare except: clause with sys.exc_info()[1] which is discouraged in Python. This change makes the exception handling more explicit by catching BaseException directly, which includes KeyboardInterrupt and SystemExit that should not be handled by the normal exception handler. Changes: - Replace bare except: with except BaseException as e: - Add explanatory comment about BaseException handling - Remove noqa: B001 comment as it's no longer needed All existing tests pass successfully. --- src/flask/app.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/flask/app.py b/src/flask/app.py index e0c193dcb7..9f5656655c 100644 --- a/src/flask/app.py +++ b/src/flask/app.py @@ -1568,8 +1568,10 @@ def wsgi_app( except Exception as e: error = e response = self.handle_exception(ctx, e) - except: # noqa: B001 - error = sys.exc_info()[1] + except BaseException as e: + # Catch BaseException (KeyboardInterrupt, SystemExit, etc.) + # that should not be handled by the exception handler + error = e raise return response(environ, start_response) finally: