Skip to content

Commit

Permalink
Capture sentry message when _exc_with_message is called without a mes…
Browse files Browse the repository at this point in the history
…sage (pypi#17068)
  • Loading branch information
di authored Nov 12, 2024
1 parent 0aaa4e2 commit 3a65d49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/unit/forklift/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ def test_exc_with_exotic_message(self):
assert exc.status_code == 400
assert exc.status == "400 look at these wild chars: ?äâ??"

def test_exc_with_missing_message(self, monkeypatch):
sentry_sdk = pretend.stub(
capture_message=pretend.call_recorder(lambda message: None)
)
monkeypatch.setattr(legacy, "sentry_sdk", sentry_sdk)
exc = legacy._exc_with_message(HTTPBadRequest, "")
assert isinstance(exc, HTTPBadRequest)
assert exc.status_code == 400
assert exc.status == "400 Bad Request"
assert sentry_sdk.capture_message.calls == [
pretend.call("Attempting to _exc_with_message without a message")
]


def test_construct_dependencies():
types = {"requires": DependencyKind.requires, "provides": DependencyKind.provides}
Expand Down
3 changes: 3 additions & 0 deletions warehouse/forklift/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ def _valid_platform_tag(platform_tag):


def _exc_with_message(exc, message, **kwargs):
if not message:
sentry_sdk.capture_message("Attempting to _exc_with_message without a message")

# The crappy old API that PyPI offered uses the status to pass down
# messages to the client. So this function will make that easier to do.
resp = exc(detail=message, **kwargs)
Expand Down

0 comments on commit 3a65d49

Please sign in to comment.