Skip to content

cbor2.CBORDecodeError should be a subclass of ValueError #299

@vytas7

Description

@vytas7

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

cbor2 version

6.0.1

Python version

3.12

What happened?

With the recently released cbor2 6.0.x, cbor2.CBORDecodeError is not a subclass of ValueError.

When using data serialization libraries like the stdlib's json, it is a common convention that .loads(...) or similar raises a subclass of ValueError (the passed value was incorrect). This used to work fine in cbor2 as well until the very recent 6.0.x releases.

How can we reproduce the bug?

Using older cbor2 (5.x), this would have worked just fine:

try:
    cbor2.loads(b'\xde\xad\xbe\xef')
except ValueError:
    print('Validation failed')

On 6.0.x, the decoding error is not caught as ValueError.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions