Skip to content

Mechanism should default to true unless set explicitly #1889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2023
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
3 changes: 2 additions & 1 deletion sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,14 @@ def single_exception_from_error_tuple(
mechanism=None, # type: Optional[Dict[str, Any]]
):
# type: (...) -> Dict[str, Any]
mechanism = mechanism or {"type": "generic", "handled": True}

if exc_value is not None:
errno = get_errno(exc_value)
else:
errno = None

if errno is not None:
mechanism = mechanism or {"type": "generic"}
mechanism.setdefault("meta", {}).setdefault("errno", {}).setdefault(
"number", errno
)
Expand Down
4 changes: 4 additions & 0 deletions tests/integrations/wsgi/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ def dogpark(environ, start_response):
assert error_event["transaction"] == "generic WSGI request"
assert error_event["contexts"]["trace"]["op"] == "http.server"
assert error_event["exception"]["values"][0]["type"] == "Exception"
assert error_event["exception"]["values"][0]["mechanism"] == {
"type": "wsgi",
"handled": False,
}
assert (
error_event["exception"]["values"][0]["value"]
== "Fetch aborted. The ball was not returned."
Expand Down
16 changes: 16 additions & 0 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ def test_event_id(sentry_init, capture_events):
assert Hub.current.last_event_id() == event_id


def test_generic_mechanism(sentry_init, capture_events):
sentry_init()
events = capture_events()

try:
raise ValueError("aha!")
except Exception:
capture_exception()

(event,) = events
assert event["exception"]["values"][0]["mechanism"] == {
"type": "generic",
"handled": True,
}


def test_option_before_send(sentry_init, capture_events):
def before_send(event, hint):
event["extra"] = {"before_send_called": True}
Expand Down