DataDog / datadogpy

The Datadog Python library
https://datadoghq.com/
Other
612 stars 304 forks source link

[statsd] Raise ValueError instead of Exception when payload is too large #730

Closed mlanicaputo closed 2 years ago

mlanicaputo commented 2 years ago

What does this PR do?

As noted in #725, statsd.event() raises a general Exception in the event that an event payload is too long. This can lead to error swallowing. This PR changes this error block to raise a ValueError instead.

Description of the Change

The statsd.event() method throws a different Exception (ValueError) in the event that a payload is too large. A test was added to test_statsd.py in order to ensure that the proper error is raised when appropriate.

Alternate Designs

Any exception could theoretically be raised, but ValueError seemed the most appropriate according to Python's guidelines. Alternatively, users of the datadog library could just catch the Exception but that is poor practice.

Possible Drawbacks

Users of the library who currently have code in place to catch a general Exception may have to change their libraries to catch the more specific ValueError.

Verification Process

A new test was added to test_statsd.py in order to ensure the viability of the error change. It tests that a payload that is too large raises the ValueError, and that a payload of allowable length does not raise a ValueError. This can be double checked by running the following from the datadogpy directory: pytest tests/unit/dogstatsd/test_statsd.py -k test_event_payload_error.

Additional Notes

Thank you for being open source!

Release Notes

Review checklist (to be filled by reviewers)

sgnn7 commented 2 years ago

@mlanicaputo Merged - thanks for your contribution!