Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions raised in 'object_hook' callback from C implementation of load result in SystemError #201

Closed
2 tasks done
kohlerjl opened this issue Dec 27, 2023 · 2 comments
Closed
2 tasks done
Labels

Comments

@kohlerjl
Copy link

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

5.5.1

Python version

3.11.6

What happened?

Python Exceptions raised in the object_hook callback in cbor2.load are not propagated correctly in the C module, and result in this exception: "SystemError: returned a result with an exception set".

I would expect the original Python exceptions to be propagated up, matching the python implementation behavior.

How can we reproduce the bug?

import pytest

import cbor2
from cbor2._decoder import loads as loads_py
from _cbor2 import loads as loads_c

def dec_objhook(decoder, d):
    raise TypeError("Unsupported type")

a = {
    'a': 1, 
    'hello': 'world', 
    'test': {'foo': 'bar'}
}
test = cbor2.dumps(a)

with pytest.raises(TypeError):
    loads_py(test, object_hook=dec_objhook)

with pytest.raises(TypeError):
    loads_c(test, object_hook=dec_objhook)
@kohlerjl kohlerjl added the bug label Dec 27, 2023
@agronholm
Copy link
Owner

This too resulted from sloppy C code. Maybe I should rewrite the C extension myself, on top of HPy.

@agronholm
Copy link
Owner

It would be even better if I could do it with Rust. But HPy doesn't support Rust just yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants