From 1222e78a15336162d190060f76c8ccee4b011d6b Mon Sep 17 00:00:00 2001 From: oTree-org Date: Mon, 29 Mar 2021 23:02:22 +0800 Subject: [PATCH] Don't use 'raise exc from None' because it suppresses exception causes (#1158) Co-authored-by: oTree-org --- starlette/endpoints.py | 2 +- starlette/exceptions.py | 2 +- starlette/middleware/errors.py | 2 +- starlette/testclient.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/starlette/endpoints.py b/starlette/endpoints.py index 1071fc35..2504dd84 100644 --- a/starlette/endpoints.py +++ b/starlette/endpoints.py @@ -71,7 +71,7 @@ class WebSocketEndpoint: break except Exception as exc: close_code = status.WS_1011_INTERNAL_ERROR - raise exc from None + raise exc finally: await self.on_disconnect(websocket, close_code) diff --git a/starlette/exceptions.py b/starlette/exceptions.py index f7ad231f..a99177a0 100644 --- a/starlette/exceptions.py +++ b/starlette/exceptions.py @@ -79,7 +79,7 @@ class ExceptionMiddleware: handler = self._lookup_exception_handler(exc) if handler is None: - raise exc from None + raise exc if response_started: msg = "Caught handled exception, but response already started." diff --git a/starlette/middleware/errors.py b/starlette/middleware/errors.py index 4217185e..30f5570c 100644 --- a/starlette/middleware/errors.py +++ b/starlette/middleware/errors.py @@ -178,7 +178,7 @@ class ServerErrorMiddleware: # We always continue to raise the exception. # This allows servers to log the error, or allows test clients # to optionally raise the error within the test case. - raise exc from None + raise exc def format_line( self, index: int, line: str, frame_lineno: int, frame_index: int diff --git a/starlette/testclient.py b/starlette/testclient.py index 1d5e90dc..bb4b75fd 100644 --- a/starlette/testclient.py +++ b/starlette/testclient.py @@ -240,7 +240,7 @@ class _ASGIAdapter(requests.adapters.HTTPAdapter): loop.run_until_complete(self.app(scope, receive, send)) except BaseException as exc: if self.raise_server_exceptions: - raise exc from None + raise exc if self.raise_server_exceptions: assert response_started, "TestClient did not receive any response." -- 2.47.3