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

fix(ffi): don't panic when running into an unknown membership state #4144

Merged
merged 2 commits into from
Oct 17, 2024

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Oct 17, 2024

Fixes #1254. This adds a bandaid in the form of converting Into impl to TryInto, and then will happily ignore errors in multiple places; unknown states are logged in warnings, so we can still get some information about it, would they become an issue in the future.

@bnjbvr bnjbvr requested a review from a team as a code owner October 17, 2024 08:46
@bnjbvr bnjbvr requested review from stefanceriu and removed request for a team October 17, 2024 08:46
Copy link

codecov bot commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.76%. Comparing base (a901506) to head (56c7f00).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4144   +/-   ##
=======================================
  Coverage   84.76%   84.76%           
=======================================
  Files         269      269           
  Lines       28848    28848           
=======================================
+ Hits        24453    24454    +1     
+ Misses       4395     4394    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it's better than a panic.

@bnjbvr
Copy link
Member Author

bnjbvr commented Oct 17, 2024

There's no way to expose the private custom variant's content anyways, right?

@bnjbvr
Copy link
Member Author

bnjbvr commented Oct 17, 2024

It was actually quite simple to handle custom memberships; not sure how the apps will like it? cc @stefanceriu @jmartinesp

Re-requesting a review, since there's a non-trivial change in there.

@bnjbvr bnjbvr requested a review from poljar October 17, 2024 09:47
@stefanceriu
Copy link
Member

Turns out you need to name that field but otherwise it shouldn't be a problem for the app
error: UniFFI only supports enum variants with named fields (or no fields at all)

MembershipState::Leave
Ok(MembershipState::Leave)
}
matrix_sdk::ruma::events::room::member::MembershipState::_Custom(_) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this is not the intended way, as the _Custom variant is hidden and instead you're supposed to use the catch all, but then other known states won't be handled (there are none other known states but the enum is non-exhaustive).

I think we can live with that despite the intentions of Ruma.

@bnjbvr bnjbvr force-pushed the bnjbvr/dont-panic-ffi-membershipstate branch from aa0f9b9 to 56c7f00 Compare October 17, 2024 13:16
@bnjbvr bnjbvr enabled auto-merge (rebase) October 17, 2024 13:16
@bnjbvr bnjbvr merged commit bdfe641 into main Oct 17, 2024
39 checks passed
@bnjbvr bnjbvr deleted the bnjbvr/dont-panic-ffi-membershipstate branch October 17, 2024 13:30
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.

Handle the _Custom(PrivOwnedStr) MembershipState case in the FFI.
3 participants