Skip to content

Commit 778fde0

Browse files
authored
Mechanism should default to true unless set explicitly (#1889)
1 parent 72455f4 commit 778fde0

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

sentry_sdk/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,13 +637,14 @@ def single_exception_from_error_tuple(
637637
mechanism=None, # type: Optional[Dict[str, Any]]
638638
):
639639
# type: (...) -> Dict[str, Any]
640+
mechanism = mechanism or {"type": "generic", "handled": True}
641+
640642
if exc_value is not None:
641643
errno = get_errno(exc_value)
642644
else:
643645
errno = None
644646

645647
if errno is not None:
646-
mechanism = mechanism or {"type": "generic"}
647648
mechanism.setdefault("meta", {}).setdefault("errno", {}).setdefault(
648649
"number", errno
649650
)

tests/integrations/wsgi/test_wsgi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ def dogpark(environ, start_response):
140140
assert error_event["transaction"] == "generic WSGI request"
141141
assert error_event["contexts"]["trace"]["op"] == "http.server"
142142
assert error_event["exception"]["values"][0]["type"] == "Exception"
143+
assert error_event["exception"]["values"][0]["mechanism"] == {
144+
"type": "wsgi",
145+
"handled": False,
146+
}
143147
assert (
144148
error_event["exception"]["values"][0]["value"]
145149
== "Fetch aborted. The ball was not returned."

tests/test_basics.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ def test_event_id(sentry_init, capture_events):
9191
assert Hub.current.last_event_id() == event_id
9292

9393

94+
def test_generic_mechanism(sentry_init, capture_events):
95+
sentry_init()
96+
events = capture_events()
97+
98+
try:
99+
raise ValueError("aha!")
100+
except Exception:
101+
capture_exception()
102+
103+
(event,) = events
104+
assert event["exception"]["values"][0]["mechanism"] == {
105+
"type": "generic",
106+
"handled": True,
107+
}
108+
109+
94110
def test_option_before_send(sentry_init, capture_events):
95111
def before_send(event, hint):
96112
event["extra"] = {"before_send_called": True}

0 commit comments

Comments
 (0)