Skip to content

Commit

Permalink
feat: replace error handling with generic ToString errors
Browse files Browse the repository at this point in the history
  • Loading branch information
coroiu committed Oct 11, 2024
1 parent 5ee793a commit 8f1ba7c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
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 @@ impl ClientCrypto {
/// 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 @@ extern "C" {
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
}
}

0 comments on commit 8f1ba7c

Please sign in to comment.