Repository navigation
chore: make error messages say what was received and what is allowed - #244
Merged
Merged
Conversation
Rewrite 63 raise statements whose messages were missing or unhelpful: - 43 passed the value and the text as two arguments, so the message printed as a tuple, for example (3, 'n must be greater than 0'). The value is now in the text: "n must be greater than 0, got 3". - 19 had no message or one of two words, such as "bad type", "bad id", "bad colorspace" and "truncated". They now name the argument, the allowed values and what was received. - the NotImplementedError in VisualServo.step names the class that must implement it. No exception types change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 7 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
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.
Summary
A survey of the 402
raisestatements insrcfound 63 whose messages were missing or unhelpful. This rewrites them. No exception type changes, and no behaviour changes except the text.ValueError(n, "n must be greater than 0"). Python prints that as the tuple(3, 'n must be greater than 0'). The value is now in an f-string:n must be greater than 0, got 3. The original wording is kept as the start of each message, so anything matching on it still works. A few sites got a better message where the old one was misleading or lacked information:ImageSpatial.convolvesaidopt is not a valid optionfor themodeargument, theborderandmodeerrors now list the allowed values, the pattern-falls-off-edge errors inImageProcessinggive the position and sizes,ImageWholeFeaturesmoment checks show bothpandq, andImage must be greyscaleinImageColorgives the number of planes.bad type(Camera.FandCamera.E),bad index,bad id,unknown detector,unknown style,unknown type,unknown colorspaceandbad colorspace(four incolor.py),bad input(draw_point),bad s(mkgrid),planes mismatch,invalid slice,solvePnP failedandtruncated(two inSources.py). Each now names the argument, what is allowed and what was received.VisualServo.stepraisedNotImplementedErrorwith no message, and now names the class that must implement it.The 13
raise StopIterationstatements inSources.pyare correct for the iterator protocol and are left alone.Tests
tests/test_error_messages.pyis new, with checks that messages name the value for a sample of the changes. Three existing tests that matched the old text (bad index,bad idand thebordermessage) are updated. The full suite passes locally (2104 passed, 33 skipped) and mypy reports no errors.Not changed
While doing this I found two unrelated faults, which are not touched here:
name2colorcatchesValueErroraround the whole conversion, so an unknown colorspace returnsNoneand its new message is never seen, andplot_spectral_locustestscolorspace in ("rg"), which is a substring test, not a tuple.This change was written with AI assistance (Claude Code) and I have reviewed the diff.
🤖 Generated with Claude Code