diff --git a/tests/unit/forklift/test_legacy.py b/tests/unit/forklift/test_legacy.py index 8994f1496316..ae2971fca913 100644 --- a/tests/unit/forklift/test_legacy.py +++ b/tests/unit/forklift/test_legacy.py @@ -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} diff --git a/warehouse/forklift/legacy.py b/warehouse/forklift/legacy.py index 10748b12b725..3dba592aa199 100644 --- a/warehouse/forklift/legacy.py +++ b/warehouse/forklift/legacy.py @@ -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)