π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Throw wasm contacts errors as tagged Error instances
Manav Rathi58e275498d6e
diff --git a/rust/bindings/wasm/ente-wasm/src/contacts.rs b/rust/bindings/wasm/ente-wasm/src/contacts.rsindex ae83ae10eb..2d1c445f1c 100644--- a/rust/bindings/wasm/ente-wasm/src/contacts.rs+++ b/rust/bindings/wasm/ente-wasm/src/contacts.rs@@ -29,7 +29,17 @@ pub enum ContactsError {impl From<ContactsError> for JsValue {fn from(e: ContactsError) -> Self {- swb::to_value(&e).unwrap_or_else(|err| JsValue::from_str(&err.to_string()))+ 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()}}diff --git a/rust/crates/accounts/src/lib.rs b/rust/crates/accounts/src/lib.rsindex 18dc4c9bb8..e5ad1fffca 100644--- a/rust/crates/accounts/src/lib.rs+++ b/rust/crates/accounts/src/lib.rs@@ -2,7 +2,7 @@//!//! Preferred usage://! - Use [`AccountsClient`] when a caller needs raw server failures, including-//! HTTP status, API code, and API message.+//! the HTTP status and API error code.//! - Use [`AuthFlow`] for CLI/e2e-style interactive orchestration where the//! library drives OTP/TOTP/passkey steps via a UI adapter.diff --git a/web/packages/wasm/tests/contacts.test.ts b/web/packages/wasm/tests/contacts.test.tsnew file mode 100644index 0000000000..4cc4c35b1b--- /dev/null+++ b/web/packages/wasm/tests/contacts.test.ts@@ -0,0 +1,14 @@+import { expect, test } from "vitest";+import { contacts_open_ctx } from "../pkg/ente_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);+ }+});