Skip to content

Commit

Permalink
Err handling refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas committed Dec 5, 2023
1 parent 83aa337 commit b33c40e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 103 deletions.
2 changes: 2 additions & 0 deletions aries/aries_vcx/src/errors/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub enum AriesVcxErrorKind {
InvalidState,
#[error("Invalid Configuration")]
InvalidConfiguration,
#[error("Authentication error")]
AuthenticationError,
#[error("Invalid JSON string")]
InvalidJson,
#[error("Invalid Option")]
Expand Down
97 changes: 0 additions & 97 deletions aries/aries_vcx/src/errors/mapping_others.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,100 +171,3 @@ impl From<AriesVcxCoreError> for AriesVcxError {
AriesVcxError::from_msg(kind, format!("AriesVcxCoreError: {}", err))
}
}

// TODO
impl From<AriesVcxError> for AriesVcxCoreError {
fn from(err: AriesVcxError) -> Self {
let kind = match err.kind() {
AriesVcxErrorKind::InvalidState => AriesVcxCoreErrorKind::InvalidState,
AriesVcxErrorKind::InvalidConfiguration => AriesVcxCoreErrorKind::InvalidConfiguration,
AriesVcxErrorKind::InvalidJson => AriesVcxCoreErrorKind::InvalidJson,
AriesVcxErrorKind::InvalidOption => AriesVcxCoreErrorKind::InvalidOption,
AriesVcxErrorKind::InvalidMessagePack => AriesVcxCoreErrorKind::InvalidMessagePack,
AriesVcxErrorKind::NotReady => AriesVcxCoreErrorKind::NotReady,
AriesVcxErrorKind::IOError => AriesVcxCoreErrorKind::IOError,
AriesVcxErrorKind::LibindyInvalidStructure => {
AriesVcxCoreErrorKind::LibindyInvalidStructure
}
AriesVcxErrorKind::InvalidLibindyParam => AriesVcxCoreErrorKind::InvalidLibindyParam,
AriesVcxErrorKind::ActionNotSupported => AriesVcxCoreErrorKind::ActionNotSupported,
AriesVcxErrorKind::InvalidInput => AriesVcxCoreErrorKind::InvalidInput,
AriesVcxErrorKind::UnimplementedFeature => AriesVcxCoreErrorKind::UnimplementedFeature,
AriesVcxErrorKind::CredDefAlreadyCreated => {
AriesVcxCoreErrorKind::CredDefAlreadyCreated
}
AriesVcxErrorKind::RevDeltaNotFound => AriesVcxCoreErrorKind::RevDeltaNotFound,
AriesVcxErrorKind::RevDeltaFailedToClear => {
AriesVcxCoreErrorKind::RevDeltaFailedToClear
}
AriesVcxErrorKind::CreateRevRegDef => AriesVcxCoreErrorKind::CreateRevRegDef,
AriesVcxErrorKind::InvalidRevocationDetails => {
AriesVcxCoreErrorKind::InvalidRevocationDetails
}
AriesVcxErrorKind::InvalidRevocationEntry => {
AriesVcxCoreErrorKind::InvalidRevocationEntry
}
AriesVcxErrorKind::InvalidRevocationTimestamp => {
AriesVcxCoreErrorKind::InvalidRevocationTimestamp
}
AriesVcxErrorKind::RevRegDefNotFound => AriesVcxCoreErrorKind::RevRegDefNotFound,
AriesVcxErrorKind::InvalidAttributesStructure => {
AriesVcxCoreErrorKind::InvalidAttributesStructure
}
AriesVcxErrorKind::InvalidProof => AriesVcxCoreErrorKind::InvalidProof,
AriesVcxErrorKind::InvalidSchema => AriesVcxCoreErrorKind::InvalidSchema,
AriesVcxErrorKind::InvalidProofCredentialData => {
AriesVcxCoreErrorKind::InvalidProofCredentialData
}
AriesVcxErrorKind::InvalidProofRequest => AriesVcxCoreErrorKind::InvalidProofRequest,
AriesVcxErrorKind::ProofRejected => AriesVcxCoreErrorKind::ProofRejected,
AriesVcxErrorKind::InvalidSchemaSeqNo => AriesVcxCoreErrorKind::InvalidSchemaSeqNo,
AriesVcxErrorKind::DuplicationSchema => AriesVcxCoreErrorKind::DuplicationSchema,
AriesVcxErrorKind::UnknownSchemaRejection => {
AriesVcxCoreErrorKind::UnknownSchemaRejection
}
AriesVcxErrorKind::InvalidGenesisTxnPath => {
AriesVcxCoreErrorKind::InvalidGenesisTxnPath
}
AriesVcxErrorKind::CreatePoolConfig => AriesVcxCoreErrorKind::CreatePoolConfig,
AriesVcxErrorKind::PoolLedgerConnect => AriesVcxCoreErrorKind::PoolLedgerConnect,
AriesVcxErrorKind::InvalidLedgerResponse => {
AriesVcxCoreErrorKind::InvalidLedgerResponse
}
AriesVcxErrorKind::LedgerItemNotFound => AriesVcxCoreErrorKind::LedgerItemNotFound,
AriesVcxErrorKind::NoPoolOpen => AriesVcxCoreErrorKind::NoPoolOpen,
AriesVcxErrorKind::PostMessageFailed => AriesVcxCoreErrorKind::PostMessageFailed,
AriesVcxErrorKind::WalletCreate => AriesVcxCoreErrorKind::WalletCreate,
AriesVcxErrorKind::WalletAccessFailed => AriesVcxCoreErrorKind::WalletAccessFailed,
AriesVcxErrorKind::InvalidWalletHandle => AriesVcxCoreErrorKind::InvalidWalletHandle,
AriesVcxErrorKind::DuplicationWallet => AriesVcxCoreErrorKind::DuplicationWallet,
AriesVcxErrorKind::WalletRecordNotFound => AriesVcxCoreErrorKind::WalletRecordNotFound,
AriesVcxErrorKind::DuplicationWalletRecord => {
AriesVcxCoreErrorKind::DuplicationWalletRecord
}
AriesVcxErrorKind::WalletNotFound => AriesVcxCoreErrorKind::WalletNotFound,
AriesVcxErrorKind::WalletAlreadyOpen => AriesVcxCoreErrorKind::WalletAlreadyOpen,
AriesVcxErrorKind::DuplicationMasterSecret => {
AriesVcxCoreErrorKind::DuplicationMasterSecret
}
AriesVcxErrorKind::DuplicationDid => AriesVcxCoreErrorKind::DuplicationDid,
AriesVcxErrorKind::LoggingError => AriesVcxCoreErrorKind::LoggingError,
AriesVcxErrorKind::EncodeError => AriesVcxCoreErrorKind::EncodeError,
AriesVcxErrorKind::UnknownError => AriesVcxCoreErrorKind::UnknownError,
AriesVcxErrorKind::InvalidDid => AriesVcxCoreErrorKind::InvalidDid,
AriesVcxErrorKind::InvalidVerkey => AriesVcxCoreErrorKind::InvalidVerkey,
AriesVcxErrorKind::InvalidNonce => AriesVcxCoreErrorKind::InvalidNonce,
AriesVcxErrorKind::InvalidUrl => AriesVcxCoreErrorKind::InvalidUrl,
AriesVcxErrorKind::SerializationError => AriesVcxCoreErrorKind::SerializationError,
AriesVcxErrorKind::NotBase58 => AriesVcxCoreErrorKind::NotBase58,
AriesVcxErrorKind::ParsingError => AriesVcxCoreErrorKind::ParsingError,
AriesVcxErrorKind::InvalidHttpResponse => AriesVcxCoreErrorKind::InvalidHttpResponse,
AriesVcxErrorKind::InvalidMessages => AriesVcxCoreErrorKind::InvalidMessages,
AriesVcxErrorKind::VdrToolsError(u32) => AriesVcxCoreErrorKind::VdrToolsError(u32),
AriesVcxErrorKind::UrsaError => AriesVcxCoreErrorKind::UrsaError,
AriesVcxErrorKind::NoAgentInformation => AriesVcxCoreErrorKind::NoAgentInformation,
AriesVcxErrorKind::InvalidMessageFormat => AriesVcxCoreErrorKind::InvalidMessageFormat,
};
AriesVcxCoreError::from_msg(kind, format!("AriesVcxError: {}", err))
}
}
15 changes: 9 additions & 6 deletions aries/aries_vcx/src/utils/encryption_envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl EncryptionEnvelope {
sender_vk, expected_vk
);
return Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidJson,
AriesVcxErrorKind::AuthenticationError,
format!(
"Message did not pass authentication check. Expected sender \
verkey was {}, but actually was {}",
Expand All @@ -229,7 +229,7 @@ impl EncryptionEnvelope {
None => {
error!("auth_unpack message was authcrypted");
return Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidJson,
AriesVcxErrorKind::AuthenticationError,
"Can't authenticate message because it was anoncrypted.",
));
}
Expand Down Expand Up @@ -388,9 +388,12 @@ pub mod unit_tests {
.await
.unwrap();

let data_unpacked =
EncryptionEnvelope::auth_unpack(&setup.wallet, envelope.0, &sender_key_alice)
.await
.unwrap_err();
let err =
EncryptionEnvelope::auth_unpack(&setup.wallet, envelope.0, &sender_key_alice).await;
assert!(err.is_err());
assert_eq!(
err.unwrap_err().kind(),
AriesVcxErrorKind::AuthenticationError
);
}
}
2 changes: 2 additions & 0 deletions aries/misc/legacy/libvcx_core/src/errors/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub enum LibvcxErrorKind {
InvalidProofRequest,
#[error("The proof was rejected")]
ProofRejected,
#[error("Authentication error")]
AuthenticationError,

// Schema
#[error("Could not create schema")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl From<AriesVcxErrorKind> for LibvcxErrorKind {
AriesVcxErrorKind::LedgerItemNotFound => LibvcxErrorKind::LedgerItemNotFound,
AriesVcxErrorKind::UrsaError => LibvcxErrorKind::UrsaError,
AriesVcxErrorKind::ProofRejected => LibvcxErrorKind::ProofRejected,
AriesVcxErrorKind::AuthenticationError => LibvcxErrorKind::AuthenticationError,
}
}
}

0 comments on commit b33c40e

Please sign in to comment.