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

handler functions should not raise python exceptions #82

Closed
ThomasWaldmann opened this issue Jul 31, 2023 · 2 comments
Closed

handler functions should not raise python exceptions #82

ThomasWaldmann opened this issue Jul 31, 2023 · 2 comments
Assignees

Comments

@ThomasWaldmann
Copy link
Collaborator

ThomasWaldmann commented Jul 31, 2023

Copied from a comment of @Nikratio in #81 :

The cdef void functions in handlers.pxi that are assigned to fuse_lowlevel_ops should never raise exceptions. Where do you see them use raise?

Nevermind, found it. I believe the affected methods are fuse_write and fuse_setxattr (which raise OverflowError if the data size doesn't fit into ssize_t (pretty unlikely) and fuse_init (which raises a RuntimeError if the kernel is too old).

Neither of these checks can easily be moved elsewhere. For the first two, I would suggest to instead return EINVAL through fuse_reply_err() and log the error (using Python's logging module). For the third, the best I can think of is to set some sort of global flag, check it in init() (after the call to fuse_session_new) and raise the exception there if set.

@Nikratio
Copy link
Contributor

Nikratio commented Aug 3, 2023

Here's an alternate patch to fix the issue: https://github.com/libfuse/pyfuse3/tree/error_handling

This tells Cython that callbacks may raise exceptions, and that exception status should be checked on return from fuse_session_process_buf. It eliminates the warnings and seems to work:

python-venv examples/hello.py ~/tmp/mnt
Traceback (most recent call last):
  File "/home/nikratio/in-progress/pyfuse3/examples/hello.py", line 157, in <module>
    main()
  File "/home/nikratio/in-progress/pyfuse3/examples/hello.py", line 148, in main
    trio.run(pyfuse3.main)
  File "/usr/lib/python3/dist-packages/trio/_core/_run.py", line 2010, in run
    raise runner.main_task_outcome.error
  File "/home/nikratio/in-progress/pyfuse3/src/_pyfuse3.py", line 43, in wrapper
    await fn(*args, **kwargs)
  File "src/pyfuse3.pyx", line 781, in main
    async with trio.open_nursery() as nursery:
  File "/usr/lib/python3/dist-packages/trio/_core/_run.py", line 850, in __aexit__
    raise combined_error_from_nursery
  File "/home/nikratio/in-progress/pyfuse3/src/_pyfuse3.py", line 43, in wrapper
    await fn(*args, **kwargs)
  File "src/internal.pxi", line 270, in _session_loop
    fuse_session_process_buf(session, &buf)
  File "src/handlers.pxi", line 53, in pyfuse3.fuse_init
    raise RuntimeError('testing error handling')
RuntimeError: testing error handling

@ThomasWaldmann
Copy link
Collaborator Author

closing, #86 with that alternative solution was just merged.

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

Successfully merging a pull request may close this issue.

2 participants