Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions scripts/find_raise_from_none.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,11 @@ def main():
for module_path in walk_package_modules():
scan_file(module_path)

# TODO: Investigate why we suppress exception chains here.
ignored_raises = {
pathlib.Path("sentry_sdk/integrations/asgi.py"): 2,
pathlib.Path("sentry_sdk/integrations/asyncio.py"): 1,
}

raise_from_none_count = {
file: len(occurences)
for file, occurences in RaiseFromNoneVisitor.line_numbers.items()
}
if raise_from_none_count != ignored_raises:
if raise_from_none_count:
exc = Exception("Detected unexpected raise ... from None.")
exc.add_note(
"Raise ... from None suppresses chained exceptions, removing valuable context."
Expand Down
15 changes: 11 additions & 4 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Based on Tom Christie's `sentry-asgi <https://github.com/encode/sentry-asgi>`.
"""

import sys
import asyncio
import inspect
from copy import deepcopy
Expand Down Expand Up @@ -37,6 +38,8 @@
logger,
transaction_from_function,
_get_installed_modules,
capture_internal_exceptions,
reraise,
)

from typing import TYPE_CHECKING
Expand Down Expand Up @@ -187,8 +190,10 @@ async def _run_app(
return await self.app(scope, receive, send)

except Exception as exc:
self._capture_lifespan_exception(exc)
raise exc from None
exc_info = sys.exc_info()
with capture_internal_exceptions():
self._capture_lifespan_exception(exc)
reraise(*exc_info)

client = sentry_sdk.get_client()
span_streaming = has_span_streaming_enabled(client.options)
Expand Down Expand Up @@ -323,8 +328,10 @@ async def _sentry_wrapped_send(
scope, receive, _sentry_wrapped_send
)
except Exception as exc:
self._capture_request_exception(exc)
raise exc from None
exc_info = sys.exc_info()
with capture_internal_exceptions():
self._capture_request_exception(exc)
reraise(*exc_info)
finally:
_asgi_middleware_applied.set(False)

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ async def _task_with_sentry_span_creation() -> "Any":
):
try:
result = await coro
except StopAsyncIteration as e:
raise e from None
except StopAsyncIteration:
raise
except Exception:
reraise(*_capture_exception())

Expand Down
Loading