Skip to content

Conversation

@uhoreg
Copy link
Member

@uhoreg uhoreg commented Sep 9, 2025

Part of the fix to element-hq/element-x-android#5099

Allows applications to distinguish between errors that occur when unlocking Secret Storage, or errors that occur when importing a secret, so that they can display appropriate feedback (or not) to the user.

  • Public API changes documented in changelogs (optional)

Signed-off-by:

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 9, 2025

CodSpeed Performance Report

Merging #5647 will improve performances by 46.97%

Comparing uhoreg:separate_import_error (c3ea78e) with main (e71d565)

Summary

⚡ 1 improvement
✅ 49 untouched

Benchmarks breakdown

Benchmark BASE HEAD Change
Restore session [memory store] 401.7 ms 273.3 ms +46.97%

@codecov
Copy link

codecov bot commented Sep 9, 2025

Codecov Report

❌ Patch coverage is 82.94574% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.30%. Comparing base (2b567e1) to head (c3ea78e).
⚠️ Report is 91 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
crates/matrix-sdk-crypto/src/olm/signing/mod.rs 35.13% 22 Missing and 2 partials ⚠️
...-sdk/src/encryption/secret_storage/secret_store.rs 73.52% 5 Missing and 4 partials ⚠️
...es/matrix-sdk/src/encryption/secret_storage/mod.rs 27.27% 8 Missing ⚠️
crates/matrix-sdk/src/encryption/recovery/mod.rs 97.70% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #5647    +/-   ##
========================================
  Coverage   88.30%   88.30%            
========================================
  Files         357      357            
  Lines       98509    98743   +234     
  Branches    98509    98743   +234     
========================================
+ Hits        86987    87196   +209     
- Misses       7389     7420    +31     
+ Partials     4133     4127     -6     

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

@uhoreg
Copy link
Member Author

uhoreg commented Sep 9, 2025

Not sure why the one unit test is failing. It looks completely unrelated to what I changed, and the test succeeds on my machine.

@uhoreg uhoreg marked this pull request as ready for review September 11, 2025 17:53
@uhoreg uhoreg requested a review from a team as a code owner September 11, 2025 17:53
@uhoreg uhoreg requested review from Hywan and removed request for a team September 11, 2025 17:53
Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

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

It looks great to me! Thanks. I've a couple of feedback, but no blocker.

Comment on lines 154 to 155
if let Some(secret_content) =
self.client.account().fetch_account_data(event_type).await.map_err(ImportError::from)?
Copy link
Member

Choose a reason for hiding this comment

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

Should be a fixup of the prefix patch.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed the commit to be a fixup. Hopefully I did it right.

Copy link
Member Author

Choose a reason for hiding this comment

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

But the CI is complaining about the fixup, so not sure what's going on. :-/

Copy link
Contributor

Choose a reason for hiding this comment

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

That's just a reminder for us to squash the fixup commits.

Comment on lines +88 to +89
#[error("Error importing a secret: {error_message}")]
Import { error_message: String },
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the drive-by comment, but don't we want to remember which secret couldn't have been imported?

Copy link
Member Author

Choose a reason for hiding this comment

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

It wasn't needed for the issue I was working on, but it does sound like it could be useful. I guess it means that I can't just use ImportError::from (or I can't just use the automatic conversion from ImportError to SecretStorageError. Is there some sort of convention that I should follow?

Copy link
Contributor

Choose a reason for hiding this comment

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

You won't be able to use the automatic conversion, but you can just map_err() from one error to the other and include the context that we can't infer automatically this way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I wasn't clear with my question. I was wondering if there was a convention for what to put in the map_err. Should I just throw an anonymous function in there? Or should I pre-define some functions in ImportError? Or something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Depends on how many times you need to do the same map, two or more use a pre-defined function, otherwise anonymous functions are fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed SecretStorageError::ImportError to have name and error fields, where name is the name of the secret that was being imported. It all seems fine except that the way SecretStore.import_secrets imports the cross signing keys is that it loads all the secrets from Secret Storage (which is fine, it calls SecretStore.get_secret individually on each secret name), but then it bundles them all up and calls OlmMachine.import_cross_signing_keys on the whole bundle. In there, it will error, for example, if one of the private keys doesn't match the public key.

But that means that I can't tell which secret caused the error, unless I modify the error type returned by OlmMachine.import_cross_signing_keys so that it contains the secret name, which means changing stuff in the crypto crate. I'm a bit hesitant to go deeper into the Rust SDK for this, since it will probably affect more stuff, but I think it's the only way to get the right information. So, just wanted to double check that it's OK for me to do that.

I think the alternative would be to hard-code something in SecretStore.import_secrets saying that it's, say, the Master key that caused the error, and hope for the best, but I'm not too excited about that either.

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 it's fine to include that in the crypto crate as well. Sure that's a breaking change but a fairly minor one.

@uhoreg uhoreg force-pushed the separate_import_error branch from dc0ff15 to 0cb753f Compare September 17, 2025 00:06
@uhoreg uhoreg requested a review from a team as a code owner September 19, 2025 21:13
@uhoreg uhoreg requested review from poljar and removed request for a team September 19, 2025 21:13
@uhoreg uhoreg force-pushed the separate_import_error branch from 6394f2c to d227f74 Compare September 23, 2025 02:28
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.

Looks good to me.

@uhoreg uhoreg force-pushed the separate_import_error branch from ee614bc to c3ea78e Compare September 23, 2025 19:07
@uhoreg uhoreg requested a review from Hywan September 23, 2025 19:37
@uhoreg
Copy link
Member Author

uhoreg commented Sep 29, 2025

Ping @Hywan: can you give this a re-review?

@uhoreg
Copy link
Member Author

uhoreg commented Oct 1, 2025

@Hywan or @poljar: one of you will need to hit the merge button because I don't have permissions in this repo

@Hywan Hywan merged commit 57d21cc into matrix-org:main Oct 2, 2025
53 of 54 checks passed
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