Skip to content

Improve wave module error messages to include the offending value #149306

@htjworld

Description

@htjworld

Summary

The wave module currently raises errors without the offending value:

wave.Error: bad # of channels
wave.Error: bad sample width
wave.Error: bad frame rate

When values come from variables, configuration, or parsed data, the
traceback shows the call site but not the actual offending value. For
Wave_read, the values are parsed from the WAV file header and never
appear in the traceback at all.

Reproduction

import wave, io
wave.open(io.BytesIO(), 'wb').setframerate(-1)
# wave.Error: bad frame rate

After this change:

wave.Error: bad frame rate: -1

I have a patch ready and will open a PR shortly.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions