-
Notifications
You must be signed in to change notification settings - Fork 237
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
Implement Lift
for flat errors
#1847
Conversation
ac9eaf1
to
1baf252
Compare
1baf252
to
4751809
Compare
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 looks great, thanks, but shouldn't we have a test that "accidentally" exercises the panic?
type FfiType = ::uniffi::RustBuffer; | ||
|
||
fn try_read(buf: &mut &[::std::primitive::u8]) -> ::uniffi::deps::anyhow::Result<Self> { | ||
panic!("Can't lift flat errors") |
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.
is it worth opening an issue around getting these errors at buildtime instead of a runtime panic?
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.
Good point, I made #1850 for this.
Maybe we could test it from Rust, but I'd be worried about trying to exercise the panic through the foreign code. Lowering a flat error from the foreign side is not allowed and implementations can choose to not implement it, segfault, or anything else. I believe all of our implementations fail in a predictable way that could be tested, but I'd be worried that adding the test could break an external bindings generator. |
We noticed a regression in `0.25.x` where dictionaries containing flat errors caused code not to be compiled. We never officially supported compound types that stored errors, but it seems better to allow the code to compile in this case. The reason this isn't supported is that we can't lift flat errors, so therefore we can't lift the dictionary. A better fix for this would be to not implement `Lift` on the dictionary in this case, which would cause a compile error rather than a runtime panic. However, that's actually not so simple as noted in the comment so I went for an easier way. This brings this very close to how they worked in `0.24.x` where we would generate an `FfiConverter` implementation for flat errors, but the lift half of it would just be panics.
4751809
to
6b75f15
Compare
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!
We noticed a regression in
0.25.x
where dictionaries containing flat errors caused code not to be compiled. We never officially supported compound types that stored errors, but it seems better to allow the code to compile in this case.The reason this isn't supported is that we can't lift flat errors, so therefore we can't lift the dictionary. A better fix for this would be to not implement
Lift
on the dictionary in this case, which would cause a compile error rather than a runtime panic. However, that's actually not so simple as noted in the comment so I went for an easier way.This brings this very close to how they worked in
0.24.x
where we would generate anFfiConverter
implementation for flat errors, but the lift half of it would just be panics.