π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Use consumer-oriented binding errors
Manav Rathi48a8a7bf8adc
diff --git a/rust/Cargo.lock b/rust/Cargo.lockindex 59432ef68d..01353cb100 100644--- a/rust/Cargo.lock+++ b/rust/Cargo.lock@@ -2501,6 +2501,7 @@ dependencies = ["md-5 0.11.0","serde","serde-wasm-bindgen",+ "thiserror 2.0.18","wasm-bindgen","wasm-bindgen-futures",]@@ -2610,6 +2611,7 @@ dependencies = ["js-sys","serde","serde-wasm-bindgen",+ "thiserror 2.0.18","wasm-bindgen","wasm-bindgen-futures",]diff --git a/rust/bindings/frb/locker/src/api/contacts.rs b/rust/bindings/frb/locker/src/api/contacts.rsindex 0959abc9fc..5da4e5c90f 100644--- a/rust/bindings/frb/locker/src/api/contacts.rs+++ b/rust/bindings/frb/locker/src/api/contacts.rs@@ -9,47 +9,26 @@ use flutter_rust_bridge::frb;#[frb]pub enum ContactsError {- Network { message: String },- Http { message: String },- Parse { message: String },- Crypto { message: String },- Auth { message: String },- InvalidInput { message: String },- MissingEncryptedData { message: String },- MissingEncryptedKey { message: String },- ProfilePictureNotFound { message: String },ActiveRecoverySession { message: String },+ Other { message: String },}impl From<ente_contacts::Error> for ContactsError {fn from(e: ente_contacts::Error) -> Self {- use ente_contacts::ErrorKind as K;- let message = ente_core::error::chain(&e);- match e.kind() {- K::Network => Self::Network { message },- K::Http => Self::Http { message },- K::Parse => Self::Parse { message },- K::Crypto => Self::Crypto { message },- K::InvalidInput => Self::InvalidInput { message },- K::MissingEncryptedData => Self::MissingEncryptedData { message },- K::MissingEncryptedKey => Self::MissingEncryptedKey { message },- K::ProfilePictureNotFound => Self::ProfilePictureNotFound { message },+ Self::Other {+ message: ente_core::error::chain(&e),}}}impl From<ente_legacy::Error> for ContactsError {fn from(e: ente_legacy::Error) -> Self {- use ente_legacy::ErrorKind as K;+ use ente_legacy::Error as E;+let message = ente_core::error::chain(&e);- match e.kind() {- K::Network => Self::Network { message },- K::Http => Self::Http { message },- K::Parse => Self::Parse { message },- K::Crypto => Self::Crypto { message },- K::Auth => Self::Auth { message },- K::InvalidInput => Self::InvalidInput { message },- K::ActiveRecoverySession => Self::ActiveRecoverySession { message },+ match e {+ E::ActiveRecoverySession => Self::ActiveRecoverySession { message },+ _ => Self::Other { message },}}}@@ -555,12 +534,9 @@ impl ContactsCtx {part_names: Vec<String>,notice_period_in_hours: i32,) -> Result<LegacyKitCreateResult, ContactsError> {- let part_names: [String; 3] =- part_names- .try_into()- .map_err(|_| ContactsError::InvalidInput {- message: "legacy kit requires exactly three part names".into(),- })?;+ let part_names: [String; 3] = part_names.try_into().map_err(|_| ContactsError::Other {+ message: "legacy kit requires exactly three part names".into(),+ })?;self.legacy.create_kit(¤t_user_key_attrs.into(),diff --git a/rust/bindings/frb/photos/src/api/contacts.rs b/rust/bindings/frb/photos/src/api/contacts.rsindex e359aefbb7..933ee4f05e 100644--- a/rust/bindings/frb/photos/src/api/contacts.rs+++ b/rust/bindings/frb/photos/src/api/contacts.rs@@ -8,31 +8,13 @@ use flutter_rust_bridge::frb;#[frb]pub enum ContactsError {- Network { message: String },- Http { message: String },- Parse { message: String },- Crypto { message: String },- Auth { message: String },- InvalidInput { message: String },- MissingEncryptedData { message: String },- MissingEncryptedKey { message: String },- ProfilePictureNotFound { message: String },- ActiveRecoverySession { message: String },+ Other { message: String },}impl From<ente_contacts::Error> for ContactsError {fn from(e: ente_contacts::Error) -> Self {- use ente_contacts::ErrorKind as K;- let message = ente_core::error::chain(&e);- match e.kind() {- K::Network => Self::Network { message },- K::Http => Self::Http { message },- K::Parse => Self::Parse { message },- K::Crypto => Self::Crypto { message },- K::InvalidInput => Self::InvalidInput { message },- K::MissingEncryptedData => Self::MissingEncryptedData { message },- K::MissingEncryptedKey => Self::MissingEncryptedKey { message },- K::ProfilePictureNotFound => Self::ProfilePictureNotFound { message },+ Self::Other {+ message: ente_core::error::chain(&e),}}}diff --git a/rust/bindings/wasm/core/Cargo.toml b/rust/bindings/wasm/core/Cargo.tomlindex 44a9d283fb..5914076292 100644--- a/rust/bindings/wasm/core/Cargo.toml+++ b/rust/bindings/wasm/core/Cargo.toml@@ -15,5 +15,6 @@ js-sys.workspace = truemd-5.workspace = trueserde.workspace = trueserde-wasm-bindgen.workspace = true+thiserror.workspace = truewasm-bindgen.workspace = truewasm-bindgen-futures.workspace = truediff --git a/rust/bindings/wasm/core/src/contacts.rs b/rust/bindings/wasm/core/src/contacts.rsindex d1407e6821..5e15083fa1 100644--- a/rust/bindings/wasm/core/src/contacts.rs+++ b/rust/bindings/wasm/core/src/contacts.rs@@ -13,77 +13,35 @@ use serde::{Deserialize, Serialize};use serde_wasm_bindgen as swb;use wasm_bindgen::prelude::*;-#[derive(Serialize)]-#[serde(tag = "kind", rename_all = "snake_case")]-pub enum ContactsError {- Network { message: String },- Http { message: String },- Parse { message: String },- Crypto { message: String },- Auth { message: String },- InvalidInput { message: String },- MissingEncryptedData { message: String },- MissingEncryptedKey { message: String },- ProfilePictureNotFound { message: String },- ActiveRecoverySession { message: String },- Serde { message: String },- Decode { message: String },+#[derive(Debug, thiserror::Error)]+pub enum Error {+ #[error(transparent)]+ Contacts(#[from] ente_contacts::Error),+ #[error(transparent)]+ Legacy(#[from] ente_legacy::Error),+ #[error(transparent)]+ Serde(#[from] swb::Error),+ #[error(transparent)]+ Decode(#[from] b64::DecodeError),}-impl From<ContactsError> for JsValue {- fn from(e: ContactsError) -> Self {- let object = match swb::to_value(&e) {- Ok(object) => object,- Err(err) => return JsValue::from_str(&err.to_string()),- };- let message = Reflect::get(&object, &JsValue::from_str("message"))- .ok()- .and_then(|message| message.as_string())- .unwrap_or_default();- let error = js_sys::Error::new(&message);- Object::assign(error.as_ref(), object.unchecked_ref());- error.into()+impl Error {+ fn name(&self) -> Option<&'static str> {+ None}-}-impl From<ente_contacts::Error> for ContactsError {- fn from(e: ente_contacts::Error) -> Self {- use ente_contacts::ErrorKind as K;- let message = ente_core::error::chain(&e);- match e.kind() {- K::Network => Self::Network { message },- K::Http => Self::Http { message },- K::Parse => Self::Parse { message },- K::Crypto => Self::Crypto { message },- K::InvalidInput => Self::InvalidInput { message },- K::MissingEncryptedData => Self::MissingEncryptedData { message },- K::MissingEncryptedKey => Self::MissingEncryptedKey { message },- K::ProfilePictureNotFound => Self::ProfilePictureNotFound { message },- }- }-}--impl From<ente_legacy::Error> for ContactsError {- fn from(e: ente_legacy::Error) -> Self {- use ente_legacy::ErrorKind as K;- let message = ente_core::error::chain(&e);- match e.kind() {- K::Network => Self::Network { message },- K::Http => Self::Http { message },- K::Parse => Self::Parse { message },- K::Crypto => Self::Crypto { message },- K::Auth => Self::Auth { message },- K::InvalidInput => Self::InvalidInput { message },- K::ActiveRecoverySession => Self::ActiveRecoverySession { message },- }+ fn message(&self) -> String {+ ente_core::error::chain(self)}}-impl From<swb::Error> for ContactsError {- fn from(e: swb::Error) -> Self {- Self::Serde {- message: e.to_string(),+impl From<Error> for JsValue {+ fn from(error: Error) -> Self {+ let js_error = js_sys::Error::new(&error.message());+ if let Some(name) = error.name() {+ js_error.set_name(name);}+ js_error.into()}}@@ -137,11 +95,9 @@ impl From<ente_contacts::ContactRecord> for ContactRecordJs {}#[wasm_bindgen]-pub async fn contacts_open_ctx(input: JsValue) -> Result<JsValue, ContactsError> {+pub async fn contacts_open_ctx(input: JsValue) -> Result<JsValue, Error> {let input: OpenContactsCtxJsInput = swb::from_value(input)?;- let master_key = b64::decode(&input.master_key_b64).map_err(|e| ContactsError::Decode {- message: e.to_string(),- })?;+ let master_key = b64::decode(&input.master_key_b64)?;let api = Arc::new(Api::new(Http::new().map_err(ente_contacts::Error::from)?,ApiConfig {@@ -177,7 +133,7 @@ pub async fn contacts_open_ctx(input: JsValue) -> Result<JsValue, ContactsError>Reflect::set(&output,&JsValue::from_str("wrappedRootContactKey"),- &swb::to_value(&result.wrapped_root_contact_key).map_err(ContactsError::from)?,+ &swb::to_value(&result.wrapped_root_contact_key)?,).expect("setting wrappedRootContactKey should not fail");Reflect::set(@@ -206,11 +162,11 @@ impl ContactsCtxHandle {self.api.set_auth(Some(Auth::User(auth_token)));}- pub fn current_wrapped_root_contact_key(&self) -> Result<JsValue, ContactsError> {+ pub fn current_wrapped_root_contact_key(&self) -> Result<JsValue, Error> {swb::to_value(&self.contacts.current_wrapped_root_contact_key()).map_err(Into::into)}- pub async fn get_diff(&self, since_time: i64, limit: u16) -> Result<JsValue, ContactsError> {+ pub async fn get_diff(&self, since_time: i64, limit: u16) -> Result<JsValue, Error> {let diff: Vec<ContactRecordJs> = self.contacts.get_diff(since_time, limit)@@ -221,24 +177,24 @@ impl ContactsCtxHandle {swb::to_value(&diff).map_err(Into::into)}- pub async fn get_profile_picture(&self, contact_id: &str) -> Result<Vec<u8>, ContactsError> {+ pub async fn get_profile_picture(&self, contact_id: &str) -> Result<Vec<u8>, Error> {self.contacts.get_profile_picture(contact_id).await.map_err(Into::into)}- pub async fn legacy_get_info(&self) -> Result<JsValue, ContactsError> {+ pub async fn legacy_get_info(&self) -> Result<JsValue, Error> {let info = self.legacy.info().await?;swb::to_value(&info).map_err(Into::into)}- pub async fn legacy_public_key(&self, email: String) -> Result<JsValue, ContactsError> {+ pub async fn legacy_public_key(&self, email: String) -> Result<JsValue, Error> {let public_key = self.legacy.public_key(&email).await?;swb::to_value(&public_key).map_err(Into::into)}- pub fn legacy_verification_id(&self, public_key_b64: String) -> Result<String, ContactsError> {+ pub fn legacy_verification_id(&self, public_key_b64: String) -> Result<String, Error> {self.legacy.verification_id(&public_key_b64).map_err(Into::into)@@ -249,7 +205,7 @@ impl ContactsCtxHandle {email: String,current_user_key_attrs: JsValue,recovery_notice_in_days: Option<i32>,- ) -> Result<(), ContactsError> {+ ) -> Result<(), Error> {let current_user_key_attrs: KeyAttributes = swb::from_value(current_user_key_attrs)?;self.legacy.add_contact(&email, ¤t_user_key_attrs, recovery_notice_in_days)@@ -262,7 +218,7 @@ impl ContactsCtxHandle {user_id: i64,emergency_contact_id: i64,state: JsValue,- ) -> Result<(), ContactsError> {+ ) -> Result<(), Error> {let state: LegacyContactState = swb::from_value(state)?;self.legacy.update_contact(user_id, emergency_contact_id, state)@@ -274,7 +230,7 @@ impl ContactsCtxHandle {&self,emergency_contact_id: i64,recovery_notice_in_days: i32,- ) -> Result<(), ContactsError> {+ ) -> Result<(), Error> {self.legacy.update_recovery_notice(emergency_contact_id, recovery_notice_in_days).await@@ -285,7 +241,7 @@ impl ContactsCtxHandle {&self,user_id: i64,emergency_contact_id: i64,- ) -> Result<(), ContactsError> {+ ) -> Result<(), Error> {self.legacy.start_recovery(user_id, emergency_contact_id).await@@ -297,7 +253,7 @@ impl ContactsCtxHandle {recovery_id: String,user_id: i64,emergency_contact_id: i64,- ) -> Result<(), ContactsError> {+ ) -> Result<(), Error> {self.legacy.stop_recovery(&recovery_id, user_id, emergency_contact_id).await@@ -309,7 +265,7 @@ impl ContactsCtxHandle {recovery_id: String,user_id: i64,emergency_contact_id: i64,- ) -> Result<(), ContactsError> {+ ) -> Result<(), Error> {self.legacy.reject_recovery(&recovery_id, user_id, emergency_contact_id).await@@ -321,7 +277,7 @@ impl ContactsCtxHandle {recovery_id: String,user_id: i64,emergency_contact_id: i64,- ) -> Result<(), ContactsError> {+ ) -> Result<(), Error> {self.legacy.approve_recovery(&recovery_id, user_id, emergency_contact_id).await@@ -332,7 +288,7 @@ impl ContactsCtxHandle {&self,recovery_id: String,current_user_key_attrs: JsValue,- ) -> Result<JsValue, ContactsError> {+ ) -> Result<JsValue, Error> {let current_user_key_attrs: KeyAttributes = swb::from_value(current_user_key_attrs)?;let bundle = self.legacy@@ -350,7 +306,7 @@ impl ContactsCtxHandle {recovery_id: String,current_user_key_attrs: JsValue,new_password: String,- ) -> Result<(), ContactsError> {+ ) -> Result<(), Error> {let current_user_key_attrs: KeyAttributes = swb::from_value(current_user_key_attrs)?;self.legacy.change_password(&recovery_id, ¤t_user_key_attrs, &new_password)diff --git a/rust/bindings/wasm/legacy/Cargo.toml b/rust/bindings/wasm/legacy/Cargo.tomlindex 2ad0e7dec7..18d98b8c7a 100644--- a/rust/bindings/wasm/legacy/Cargo.toml+++ b/rust/bindings/wasm/legacy/Cargo.toml@@ -12,5 +12,6 @@ ente-wasm-log.workspace = truejs-sys.workspace = trueserde.workspace = trueserde-wasm-bindgen.workspace = true+thiserror.workspace = truewasm-bindgen.workspace = truewasm-bindgen-futures.workspace = truediff --git a/rust/bindings/wasm/legacy/src/lib.rs b/rust/bindings/wasm/legacy/src/lib.rsindex c214ac9da6..4a29bd9ed6 100644--- a/rust/bindings/wasm/legacy/src/lib.rs+++ b/rust/bindings/wasm/legacy/src/lib.rs@@ -1,54 +1,38 @@use ente_legacy::{LegacyKitRecoveryClient, LegacyKitShare};-use js_sys::Reflect;use serde::Deserialize;use serde_wasm_bindgen as swb;use wasm_bindgen::prelude::*;use ente_wasm_log as _;-pub struct LegacyError {- kind: &'static str,- message: String,+#[derive(Debug, thiserror::Error)]+pub enum Error {+ #[error(transparent)]+ Legacy(#[from] ente_legacy::Error),+ #[error(transparent)]+ Serde(#[from] swb::Error),}-impl From<LegacyError> for JsValue {- fn from(error: LegacyError) -> Self {- let js_error = js_sys::Error::new(&error.message);- Reflect::set(- js_error.as_ref(),- &JsValue::from_str("kind"),- &JsValue::from_str(error.kind),- )- .expect("setting error kind should not fail");- js_error.into()+impl Error {+ fn name(&self) -> Option<&'static str> {+ match self {+ Self::Legacy(ente_legacy::Error::LegacyKitInactive) => Some("legacy_kit_inactive"),+ _ => None,+ }}-}-impl From<ente_legacy::Error> for LegacyError {- fn from(error: ente_legacy::Error) -> Self {- use ente_legacy::ErrorKind as K;- let kind = match error.kind() {- K::Network => "network",- K::Http => "http",- K::Parse => "parse",- K::Crypto => "crypto",- K::Auth => "auth",- K::InvalidInput => "invalid_input",- K::ActiveRecoverySession => "active_recovery_session",- };- Self {- kind,- message: ente_core::error::chain(&error),- }+ fn message(&self) -> String {+ ente_core::error::chain(self)}}-impl From<swb::Error> for LegacyError {- fn from(error: swb::Error) -> Self {- Self {- kind: "serde",- message: error.to_string(),+impl From<Error> for JsValue {+ fn from(error: Error) -> Self {+ let js_error = js_sys::Error::new(&error.message());+ if let Some(name) = error.name() {+ js_error.set_name(name);}+ js_error.into()}}@@ -64,9 +48,7 @@ struct OpenLegacyKitRecoveryInput {}#[wasm_bindgen]-pub async fn legacy_kit_open_recovery(- input: JsValue,-) -> Result<LegacyKitRecoveryHandle, LegacyError> {+pub async fn legacy_kit_open_recovery(input: JsValue) -> Result<LegacyKitRecoveryHandle, Error> {let input: OpenLegacyKitRecoveryInput = swb::from_value(input)?;let client = LegacyKitRecoveryClient::new_with_headers(input.base_url,@@ -87,19 +69,16 @@ pub struct LegacyKitRecoveryHandle {#[wasm_bindgen]impl LegacyKitRecoveryHandle {- pub fn session(&self) -> Result<JsValue, LegacyError> {- swb::to_value(self.inner.session()).map_err(Into::into)+ pub fn session(&self) -> Result<JsValue, Error> {+ Ok(swb::to_value(self.inner.session())?)}- pub async fn refresh_session(&self) -> Result<JsValue, LegacyError> {+ pub async fn refresh_session(&self) -> Result<JsValue, Error> {let session = self.inner.refresh_session().await?;- swb::to_value(&session).map_err(Into::into)+ Ok(swb::to_value(&session)?)}- pub async fn change_password(&self, new_password: String) -> Result<(), LegacyError> {- self.inner- .change_password(&new_password)- .await- .map_err(Into::into)+ pub async fn change_password(&self, new_password: String) -> Result<(), Error> {+ Ok(self.inner.change_password(&new_password).await?)}}diff --git a/rust/crates/contacts/src/error.rs b/rust/crates/contacts/src/error.rsindex e7bd93d619..367601a77f 100644--- a/rust/crates/contacts/src/error.rs+++ b/rust/crates/contacts/src/error.rs@@ -25,32 +25,4 @@ pub enum Error {ProfilePictureNotFound,}-#[derive(Clone, Copy, Debug, PartialEq, Eq)]-pub enum ErrorKind {- Network,- Http,- Parse,- Crypto,- InvalidInput,- MissingEncryptedData,- MissingEncryptedKey,- ProfilePictureNotFound,-}--impl Error {- pub fn kind(&self) -> ErrorKind {- match self {- Error::Http(http::Error::Network(_)) => ErrorKind::Network,- Error::Http(http::Error::Parse(_)) => ErrorKind::Parse,- Error::Http(_) => ErrorKind::Http,- Error::Crypto(_) => ErrorKind::Crypto,- Error::Base64Decode(_) => ErrorKind::Crypto,- Error::InvalidInput(_) => ErrorKind::InvalidInput,- Error::MissingEncryptedData => ErrorKind::MissingEncryptedData,- Error::MissingEncryptedKey => ErrorKind::MissingEncryptedKey,- Error::ProfilePictureNotFound => ErrorKind::ProfilePictureNotFound,- }- }-}-pub type Result<T> = std::result::Result<T, Error>;diff --git a/rust/crates/contacts/src/lib.rs b/rust/crates/contacts/src/lib.rsindex 11c3d06f2d..38caf82727 100644--- a/rust/crates/contacts/src/lib.rs+++ b/rust/crates/contacts/src/lib.rs@@ -5,5 +5,5 @@ pub mod models;pub mod transport;pub use client::{ContactsClient, OpenContactsInput, OpenContactsResult, RootKeySource};-pub use error::{Error, ErrorKind, Result};+pub use error::{Error, Result};pub use models::{AttachmentType, ContactData, ContactRecord, WrappedRootContactKey};diff --git a/rust/crates/contacts/tests/contacts.rs b/rust/crates/contacts/tests/contacts.rsindex c2330ac210..373cc44360 100644--- a/rust/crates/contacts/tests/contacts.rs+++ b/rust/crates/contacts/tests/contacts.rs@@ -595,6 +595,17 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO.iter().all(|kit| kit.id != waiting_kit.kit.id));+ let inactive_error = match recovery_client+ .open_from_shares(&waiting_kit.shares[0..2], None)+ .await+ {+ Ok(_) => panic!("deleted legacy kit recovery unexpectedly opened"),+ Err(error) => error,+ };+ assert!(matches!(+ inactive_error,+ ente_legacy::Error::LegacyKitInactive+ ));let immediate_kit = owner.owner_ctxdiff --git a/rust/crates/legacy/src/error.rs b/rust/crates/legacy/src/error.rsindex ad615acc39..f0ee1650d0 100644--- a/rust/crates/legacy/src/error.rs+++ b/rust/crates/legacy/src/error.rs@@ -20,31 +20,9 @@ pub enum Error {#[error("a recovery is already in progress")]ActiveRecoverySession,-}--#[derive(Clone, Copy, Debug, PartialEq, Eq)]-pub enum ErrorKind {- Network,- Http,- Parse,- Crypto,- Auth,- InvalidInput,- ActiveRecoverySession,-}-impl Error {- pub fn kind(&self) -> ErrorKind {- match self {- Error::Http(http::Error::Network(_)) => ErrorKind::Network,- Error::Http(http::Error::Parse(_)) => ErrorKind::Parse,- Error::Http(_) => ErrorKind::Http,- Error::Crypto(_) | Error::Base64Decode(_) => ErrorKind::Crypto,- Error::Accounts(_) => ErrorKind::Auth,- Error::InvalidInput(_) => ErrorKind::InvalidInput,- Error::ActiveRecoverySession => ErrorKind::ActiveRecoverySession,- }- }+ #[error("legacy kit is inactive")]+ LegacyKitInactive,}pub type Result<T> = std::result::Result<T, Error>;diff --git a/rust/crates/legacy/src/kit/mod.rs b/rust/crates/legacy/src/kit/mod.rsindex f732ea00ed..74717c4839 100644--- a/rust/crates/legacy/src/kit/mod.rs+++ b/rust/crates/legacy/src/kit/mod.rs@@ -7,7 +7,7 @@ use ente_accounts::auth::{self, KeyAttributes, SrpSession};use ente_core::b64;use ente_core::{crypto::{self, SecretString, SecretVec, kdf, sealed, secretbox},- http::{Api, ApiConfig, Http},+ http::{Api, ApiConfig, Http, Response},};use uuid::Uuid;@@ -177,15 +177,15 @@ impl LegacyKitRecoveryClient {let first_share = shares.first().ok_or_else(|| {Error::InvalidInput("at least two legacy kit shares are required".into())})?;- let challenge = self+ let response = self.api.post("/legacy-kits/recovery/challenge").json(&LegacyKitChallengeRequest {kit_id: first_share.kit_id.clone(),}).send()- .await?- .error_for_status()?+ .await?;+ let challenge = active_kit_response(response)?.json::<LegacyKitChallengeResponse>().await?;self.open_from_encrypted_challenge(shares, &challenge.encrypted_challenge, email)@@ -220,7 +220,7 @@ impl LegacyKitRecoveryHandle {}pub async fn refresh_session(&self) -> Result<LegacyKitRecoverySession> {- Ok(self+ let response = self.api.post("/legacy-kits/recovery/session").json(&LegacyKitSessionRequest {@@ -228,10 +228,8 @@ impl LegacyKitRecoveryHandle {session_token: self.session_token.as_ref().to_owned(),}).send()- .await?- .error_for_status()?- .json()- .await?)+ .await?;+ Ok(response.error_for_status()?.json().await?)}pub async fn recovery_bundle(&self) -> Result<LegacyKitRecoveryBundle> {@@ -243,7 +241,8 @@ impl LegacyKitRecoveryHandle {session_token: self.session_token.as_ref().to_owned(),}).send()- .await?+ .await?;+ let response = response.error_for_status()?.json::<LegacyKitRecoveryInfoResponse>().await?;@@ -273,7 +272,7 @@ impl LegacyKitRecoveryHandle {let srp_user_id = Uuid::new_v4().to_string();let (mut srp_session, setup_request) =password_reset_setup_request(&srp_user_id, &login_key)?;- let init_response = self+ let response = self.api.post("/legacy-kits/recovery/init-change-password").json(&LegacyKitInitChangePasswordRequest {@@ -282,7 +281,8 @@ impl LegacyKitRecoveryHandle {setup_srp_request: setup_request,}).send()- .await?+ .await?;+ let init_response = response.error_for_status()?.json::<LegacyKitSetupSrpResponse>().await?;@@ -294,7 +294,7 @@ impl LegacyKitRecoveryHandle {mem_limit: updated_key_attrs.mem_limit,ops_limit: updated_key_attrs.ops_limit,};- let change_response = self+ let response = self.api.post("/legacy-kits/recovery/change-password").json(&LegacyKitChangePasswordRequest {@@ -307,7 +307,8 @@ impl LegacyKitRecoveryHandle {},}).send()- .await?+ .await?;+ let change_response = response.error_for_status()?.json::<LegacyKitChangePasswordResponse>().await?;@@ -338,8 +339,8 @@ impl LegacyKitRecoveryClient {email,}).send()- .await?- .error_for_status()?+ .await?;+ let response = active_kit_response(response)?.json::<LegacyKitOpenRecoveryResponse>().await?;Ok(LegacyKitRecoveryHandle {@@ -351,6 +352,14 @@ impl LegacyKitRecoveryClient {}}+fn active_kit_response(response: Response) -> Result<Response> {+ if response.status() == 404 {+ Err(Error::LegacyKitInactive)+ } else {+ Ok(response.error_for_status()?)+ }+}+pub(crate) fn validate_notice_period(hours: i32) -> Result<()> {if LEGACY_KIT_NOTICE_OPTIONS.contains(&hours) {Ok(())diff --git a/rust/crates/legacy/src/lib.rs b/rust/crates/legacy/src/lib.rsindex 9dc28e4f4a..feed19fa20 100644--- a/rust/crates/legacy/src/lib.rs+++ b/rust/crates/legacy/src/lib.rs@@ -7,7 +7,7 @@ pub mod models;pub mod transport;pub use client::LegacyClient;-pub use error::{Error, ErrorKind, Result};+pub use error::{Error, Result};pub use kit::{LegacyKitRecoveryClient, LegacyKitRecoveryHandle};pub use kit_models::{LEGACY_KIT_PAYLOAD_VERSION, LegacyKit, LegacyKitCreateResult, LegacyKitMetadata,diff --git a/web/apps/legacy/src/pages/index.tsx b/web/apps/legacy/src/pages/index.tsxindex ce76bd3424..2ce26c98e1 100644--- a/web/apps/legacy/src/pages/index.tsx+++ b/web/apps/legacy/src/pages/index.tsx@@ -57,11 +57,6 @@ const slotLabels: Record<SlotID, string> = {const slotNumbers: Record<SlotID, number> = { first: 1, second: 2 };-const inactiveLegacyKitRequestPaths = [- "/legacy-kits/recovery/challenge",- "/legacy-kits/recovery/open",-];-const getErrorMessage = (error: unknown) =>error instanceof Error? error.message@@ -69,16 +64,8 @@ const getErrorMessage = (error: unknown) =>? String(error.message): "Something went wrong.";-const isInactiveLegacyKitError = (error: unknown) => {- const message = getErrorMessage(error).toLowerCase();- return (- message.includes("legacy kit not found") ||- (message.includes("http 404") &&- inactiveLegacyKitRequestPaths.some((path) =>- message.includes(path),- ))- );-};+const isInactiveLegacyKitError = (error: unknown) =>+ error instanceof Error && error.name == "legacy_kit_inactive";const parseSlotCode = (rawCode: string): Pick<SheetSlot, "error" | "share"> => {if (!rawCode.trim()) {diff --git a/web/packages/wasm/core/tests/contacts.test.ts b/web/packages/wasm/core/tests/contacts.test.tsdeleted file mode 100644index 03145dfe96..0000000000--- a/web/packages/wasm/core/tests/contacts.test.ts+++ /dev/null@@ -1,14 +0,0 @@-import { expect, test } from "vitest";-import { contacts_open_ctx } from "../pkg/ente_core_wasm.js";--test("contacts errors cross as an Error carrying a tagged shape", async () => {- try {- await contacts_open_ctx(42);- expect.unreachable();- } catch (e) {- expect(e).toBeInstanceOf(Error);- expect(e).toMatchObject({ kind: "serde" });- expect((e as Error).message).not.toBe("");- expect(String(e)).toContain((e as Error).message);- }-});