Skip to content

UniFFI don't panic on failed lift #373

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dani-garcia
Copy link
Member

🎟️ Tracking

📔 Objective

UniFFI uses the custom_type! macro to convert request/response types. The request conversion is allowed to fail which should produce an error in the apps, but there are cases where it would produce a panic instead. The cases are:

  • If the FFI function doesn't return a result, then UniFFI produces a panic.
  • If the Error type of the function is different than the Error type in custom_type!, then UniFFI produces a panic.

One way to fix this is to have the custom_type! calls return bitwarden_uniffi::error::BitwardenError, but this isn't possible as core and crypto can't depend on uniffi due to circular dependency issues.

This PR makes the uniffi crate register an error conversion function during client initialization, thanks to the use of a new uniffi-error crate. It also updates all the calls to custom_type! to use this new error conversion.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation
    team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed
    issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@dani-garcia dani-garcia requested review from a team as code owners July 31, 2025 20:07
Copy link
Contributor

github-actions bot commented Jul 31, 2025

Logo
Checkmarx One – Scan Summary & Detailsee8d65e5-c74f-4fb0-8165-001e84259e07

Great job! No new security vulnerabilities introduced in this pull request

Copy link

Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 0% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.79%. Comparing base (d3d7976) to head (6c9e41a).

Files with missing lines Patch % Lines
crates/bitwarden-uniffi-error/src/lib.rs 0.00% 16 Missing ⚠️
crates/bitwarden-uniffi/src/lib.rs 0.00% 6 Missing ⚠️
crates/bitwarden-uniffi/src/vault/ciphers.rs 0.00% 5 Missing ⚠️
crates/bitwarden-crypto/src/uniffi_support.rs 0.00% 4 Missing ⚠️
crates/bitwarden-core/src/uniffi_support.rs 0.00% 2 Missing ⚠️
crates/bitwarden-uniffi/src/error.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #373      +/-   ##
==========================================
- Coverage   73.95%   73.79%   -0.16%     
==========================================
  Files         252      253       +1     
  Lines       21574    21595      +21     
==========================================
- Hits        15955    15937      -18     
- Misses       5619     5658      +39     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@Thomas-Avery Thomas-Avery left a comment

Choose a reason for hiding this comment

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

Changes look good from the KM perspective.


pub use anyhow::Error;

/// Configure an error converter to conver errors in calls to [`uniffi::custom_type!`] into the main
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Configure an error converter to conver errors in calls to [`uniffi::custom_type!`] into the main
/// Configure an error converter to convert errors in calls to [`uniffi::custom_type!`] into the main

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