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

Generic wasm error alternative #1130

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions crates/bitwarden-wasm-internal/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,12 @@
/// Initialization method for the user crypto. Needs to be called before any other crypto
/// operations.
pub async fn initialize_user_crypto(&self, req: InitUserCryptoRequest) -> Result<()> {
Ok(self
.0
.crypto()
.initialize_user_crypto(req)
.await
.map_err(bitwarden_core::Error::EncryptionSettings)?)
Ok(self.0.crypto().initialize_user_crypto(req).await?)

Check warning on line 19 in crates/bitwarden-wasm-internal/src/crypto.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/crypto.rs#L19

Added line #L19 was not covered by tests
}

/// Initialization method for the organization crypto. Needs to be called after
/// `initialize_user_crypto` but before any other crypto operations.
pub async fn initialize_org_crypto(&self, req: InitOrgCryptoRequest) -> Result<()> {
Ok(self
.0
.crypto()
.initialize_org_crypto(req)
.await
.map_err(bitwarden_core::Error::EncryptionSettings)?)
Ok(self.0.crypto().initialize_org_crypto(req).await?)

Check warning on line 25 in crates/bitwarden-wasm-internal/src/crypto.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/crypto.rs#L25

Added line #L25 was not covered by tests
}
}
22 changes: 8 additions & 14 deletions crates/bitwarden-wasm-internal/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,18 @@
fn new(message: String) -> WasmError;
}

pub type Result<T, E = Error> = std::result::Result<T, E>;
pub type Result<T, E = GenericError> = std::result::Result<T, E>;

pub struct Error(bitwarden::error::Error);
pub struct GenericError(pub String);

impl From<bitwarden::error::Error> for Error {
fn from(error: bitwarden::error::Error) -> Self {
Self(error)
impl<T: ToString> From<T> for GenericError {
fn from(error: T) -> Self {
GenericError(error.to_string())

Check warning on line 19 in crates/bitwarden-wasm-internal/src/error.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/error.rs#L18-L19

Added lines #L18 - L19 were not covered by tests
}
}

impl From<bitwarden::Error> for Error {
fn from(error: bitwarden::Error) -> Self {
Self(error.into())
}
}

impl From<Error> for JsValue {
fn from(error: Error) -> Self {
WasmError::new(error.0.to_string()).into()
impl From<GenericError> for JsValue {
fn from(error: GenericError) -> Self {
WasmError::new(error.0).into()

Check warning on line 25 in crates/bitwarden-wasm-internal/src/error.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/error.rs#L24-L25

Added lines #L24 - L25 were not covered by tests
}
}
Loading