gh-149306: Improve error messages in wave module to include the offending value#149307
Open
htjworld wants to merge 2 commits intopython:mainfrom
Open
gh-149306: Improve error messages in wave module to include the offending value#149307htjworld wants to merge 2 commits intopython:mainfrom
htjworld wants to merge 2 commits intopython:mainfrom
Conversation
… offending value Include the offending value in wave.Error messages raised by Wave_read._read_fmt_chunk and Wave_write setters (setnchannels, setsampwidth, setframerate). For setframerate, the original value is shown rather than the rounded one to aid debugging.
cc28830 to
d1ba708
Compare
…e-error-messages
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
Include the offending value in
wave.Errormessages raised by:Wave_read._read_fmt_chunk(parses WAV file header)Wave_write.setnchannelsWave_write.setsampwidthWave_write.setframerateBefore:
After:
Motivation
Wave_read: Values come from the WAV file header — they never appearin the traceback. The error message is the only debugging clue.
Wave_write: When values originate from variables, configuration files,or parsed data rather than literals, the traceback shows the call site but
not the value itself. For example,
w.setframerate(config['rate'])raisesbad frame ratewith no indication of whatconfig['rate']was.This extends the clear-feedback approach introduced in gh-144976, which fixed
the validation order in
setframerateto raise immediately at the point ofthe mistake. Showing the offending value is the natural next step.
For
setframerate, the original value (beforeint(round())) is shown ratherthan the rounded result, so callers see exactly what they passed.
Precedent
statistics:raise StatisticsError(f'No negative inputs allowed: {x!r}')(statistics: Fix geometric_mean() error message for negative inputs #149246)asyncio:raise ValueError(f'A Stream Socket was expected, got {sock!r}')Notes
bad sample widthpredates this PR and can be addressed separately.NaN/Infhandling insetframerateis pre-existing behaviour and out of scope here.