-
Notifications
You must be signed in to change notification settings - Fork 792
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
Make PanicException
exportable
#3519
Comments
Overall the plan which we came up with in #3073 was to publish I think we're all on board with that plan, so I think all that's waiting is an implementation 😄 |
What do we want that implementation to look like? A pure python package, or something written in rust (either with pyo3 or pyo3-ffi)? |
I think |
Actually, my point for the issue was quite the opposite. I think library authors could just add m.add("PanicError", py.get_type::<pyo3::panic::PanicException>())?; to their module if they want it to be catch by their users, and that we don't need a But it was very late, and I totally forgot that it was possible to export |
They can, but from experience the reason why users occasionally want to catch panics is because they have some kind of production service which they don't want to have any downtime. I think asking them to add exception catching for N different Polars actually already does export |
Catching a Anyway, I've pretty much no experience in pyo3 library (I need coroutine support to build my first one), so my opinion has not so much value here. |
Catching panics should be a last-ditch effort in an "outer" handler anyway, akin to catching |
This argument has already been used, but I don't understand it. What's the interest of catching exceptions from library you don't know, except when you do a global catch like
I think providing a PyO3 specific error while ignoring other Rust/C++/C/Fortran/Zig/Nim/etc. bindings doesn't really help, because it's either too specific (only PyO3), or too broad (all PyO3 libraries mixed). I can't think of any use case where someone will write Also, let's imagine that some library with a PyO3 backend is rewritten in Zig (because why not), you see the consequence... |
Well said and I think this could be added to the discussion in #3057 which covers a lot of ground of why users of PyO3 want this. I think w.r.t. your argument, their main point is that EDIT: So exporting it is a compromise giving control over its interpretation to downstream code instead of e.g. adjusting it via magic environment variables or build time flags. |
Agreed, and I think the insight that it's an implementation detail which is leaking out is true. I think this is also a result of differing needs between PyO3 and library authors:
I think if library authors were instead working to minimise panics the volume of debate on whether to catch
Maybe there is also a way where we can let individual PyO3 extensions register their own |
I have not had the time to really form an opinion on all of this, but I think this would even be easier by using our existing |
Why not just add a |
I appreciate the per-function attribute makes it delightfully awkward for users but I think that might be a step too far in bad ergonomics. We cannot win 😂 |
I'm having trouble catching it in Python for https://jpegxl.info/test-page/Webkit-logo-P3.jxl
If i catch BaseException, Pylint (W0718:broad-exception-caught Catching too general exception) and Sonarlint (python:S5754 Catch a more specific exception or reraise the exception) complain. Solved using my current code: # pylint: disable=W0718
except (
tkinter.TclError,
IOError,
MemoryError, # NOSONAR
EOFError, # NOSONAR
ValueError, # NOSONAR
BufferError, # NOSONAR
OSError, # NOSONAR
BaseException, # NOSONAR # https://github.com/PyO3/pyo3/issues/3519
) as ex: |
It's a common practice for Python libraries to define custom exceptions.
PanicException
is not really different of other custom exception (except it is derived fromBaseException
), so it could be made exportable, to be imported in Python code.As a side-effect, every library compiled with PyO3 will thus have a unique
PanicException
, but is it an issue? After all, a panic from library A doesn't necessarily means the same than a panic from library B. Also, it could be exported with a different name, more related to the context of the library.(See #1632 (comment) for the context of this issue)
The text was updated successfully, but these errors were encountered: