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

Don't panic for try_lift errors #2190

Merged
merged 1 commit into from
Jul 24, 2024
Merged

Conversation

bendk
Copy link
Contributor

@bendk bendk commented Jul 17, 2024

This avoids crashing for consumers that set panic=abort (Firefox).

  • Updated the Err type for rust_call. The closure can now return an internal error. The only way to signal an internal error before was to panic.
  • Reworked the LowerReturn trait and the future code to work with the new system.
  • Added a type for argument lift errors, this makes the rustfuture signatures nicer.

@bendk bendk requested a review from a team as a code owner July 17, 2024 14:15
@bendk bendk requested review from jeddai and removed request for a team July 17, 2024 14:15
This avoids crashing for consumers that set panic=abort (Firefox).

- Updated the Err type for `rust_call`.  The closure can now return an
  internal error.  The only way to signal an internal error before was
  to panic.
- Reworked the `LowerReturn` trait and the future code to work with the
  new system.
- Added a type for argument lift errors, this makes the rustfuture
  signatures nicer.
@bendk bendk force-pushed the no-panic-on-lift-errors branch from 0e554e5 to cf59498 Compare July 17, 2024 16:36
@bendk bendk merged commit b97973d into mozilla:main Jul 24, 2024
5 checks passed
@bendk bendk deleted the no-panic-on-lift-errors branch July 26, 2024 18:35
@pierre-wehbe
Copy link

@mhammond Would this allow flat_errors to be lifted by any chance?

Can't lift flat errors
rustPanic("Can\'t lift flat errors")

@mhammond
Copy link
Member

@mhammond Would this allow flat_errors to be lifted by any chance?

I doubt it - that's largely impossible IIUC - consider that we allow a flat enum to have any type - eg

enum Foo {
  Variant(SomeOtherType),
}

Where SomeOtherType can be literally anything that works in Rust - it doesn't need to be a Uniffi type. This works because it's flat - we just lower the variant discriminator without SomeOtherType at all. This makes it almost impossible to lift - lifting implies somehow we are able to create Variant(SomeOtherType) without a value for SomeOtherType.

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 this pull request may close these issues.

3 participants