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)
[ ] Feature or bug fix MUST have appropriate tests (unit, integration, etc...)
[ ] PR title must be written as a CHANGELOG entry (see why)
[ ] Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
[ ] PR must have one changelog/ label attached. If applicable it should have the backward-incompatible label attached.
[ ] PR should not have do-not-merge/ label attached.
[ ] If Applicable, issue must have kind/ and severity/ labels attached at least.
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)
changelog/
label attached. If applicable it should have thebackward-incompatible
label attached.do-not-merge/
label attached.kind/
andseverity/
labels attached at least.