forked from Aperture-Finance/Aperture-Lens
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(error): Add custom error handling to improve robustness
Introduce `Error` enum for consistent error management and integrate `thiserror` for better error descriptions. Update functions to use the new error handling, replacing `anyhow::Result` with `Result<T, Error>`, and refactor tests to unwrap results for simplicity.
- Loading branch information
Showing
7 changed files
with
129 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use alloy::{contract::Error as ContractError, sol_types::Error as AbiError}; | ||
|
||
#[derive(Debug)] | ||
#[cfg_attr(feature = "std", derive(thiserror::Error))] | ||
pub enum Error { | ||
/// An error occurred retrieving the revert data. | ||
#[cfg_attr(feature = "std", error("Invalid revert data"))] | ||
InvalidRevertData, | ||
|
||
/// An error occurred ABI encoding or decoding. | ||
#[cfg_attr(feature = "std", error("{0}"))] | ||
AbiError(AbiError), | ||
|
||
/// An error occurred interacting with a contract over RPC. | ||
#[cfg_attr(feature = "std", error("{0}"))] | ||
ContractError(ContractError), | ||
} | ||
|
||
impl From<AbiError> for Error { | ||
#[inline] | ||
fn from(e: AbiError) -> Self { | ||
Self::AbiError(e) | ||
} | ||
} | ||
|
||
impl From<ContractError> for Error { | ||
#[inline] | ||
fn from(e: ContractError) -> Self { | ||
Self::ContractError(e) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.