-
Notifications
You must be signed in to change notification settings - Fork 240
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
Python error handling #215
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uniffi_bindgen/src/bindings/python/templates/TopLevelFunctionTemplate.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is almost there! Awesome job! 🚀
Dropped a couple of comments, mainly requesting changes for the error code matching and freeing but this is looking good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how this is coming together! I think you can simplify the code by using a stateless helper function rather than the stateful RustErrorHelper
method, see my comments inline below.
Thanks for the feedback, it's probably fine now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I left a couple of very minor comments below, but this looks really good overall.
(I'm going to wait to hear from @linacambridge over in #221 to make sure we don't generate merge conflicts with her work, before merging this)
try { | ||
sub(0, 2) | ||
throw RuntimeException("Should have thrown a IntegerOverflow exception!") | ||
} catch (e: ArithmeticErrorException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In swift and python we explicitly test that this was the IntegerOverflow
variant, but here we test only that it was an ArithmeticError
. Does it work if we catch ArithmeticErrorException.IntegerOverflow
here like the other languages do?
(I note that the todolist example has a similar problem, but we don't need to fix that here)
_UniFFILib.{{ func.ffi_func().name() }}({% call _arg_list_ffi_call(func.arguments()) -%}) | ||
{%- match func.throws() -%} | ||
{%- when Some with (e) -%} | ||
rust_call_with_error({{ e|class_name_py }},_UniFFILib.{{ func.ffi_func().name() }},{% call _arg_list_ffi_call(func) -%}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I really like how this worked out in practice 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR add support for Python error handling
Closes #202
Closes #206