[statsd] Raise ValueError instead of Exception when payload is too large#730
Merged
sgnn7 merged 5 commits intoDataDog:masterfrom Jul 29, 2022
mlanicaputo:master
Merged
[statsd] Raise ValueError instead of Exception when payload is too large#730sgnn7 merged 5 commits intoDataDog:masterfrom mlanicaputo:master
sgnn7 merged 5 commits intoDataDog:masterfrom
mlanicaputo:master
Conversation
sgnn7
requested changes
Jul 28, 2022
Contributor
sgnn7
left a comment
There was a problem hiding this comment.
Hey @mlanicaputo! I left a comment on the PR but it's a minor nit
sgnn7
approved these changes
Jul 29, 2022
Contributor
|
@mlanicaputo Merged - thanks for your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-incompatiblelabel attached.do-not-merge/label attached.kind/andseverity/labels attached at least.