Skip to content

Commit 8367d4a

Browse files
fix: implement proper Debug and Display traits for PythReceiverError to show meaningful error messages in tests
Co-Authored-By: [email protected] <[email protected]>
1 parent c1e6bad commit 8367d4a

File tree

1 file changed

+60
-2
lines changed
  • target_chains/stylus/contracts/pyth-receiver/src

1 file changed

+60
-2
lines changed

target_chains/stylus/contracts/pyth-receiver/src/error.rs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,66 @@ pub enum PythReceiverError {
3030
}
3131

3232
impl core::fmt::Debug for PythReceiverError {
33-
fn fmt(&self, _: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
34-
Ok(())
33+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
34+
match self {
35+
PythReceiverError::PriceUnavailable => write!(f, "PriceUnavailable"),
36+
PythReceiverError::InvalidUpdateData => write!(f, "InvalidUpdateData"),
37+
PythReceiverError::VaaVerificationFailed => write!(f, "VaaVerificationFailed"),
38+
PythReceiverError::InvalidVaa => write!(f, "InvalidVaa"),
39+
PythReceiverError::InvalidWormholeMessage => write!(f, "InvalidWormholeMessage"),
40+
PythReceiverError::InvalidMerkleProof => write!(f, "InvalidMerkleProof"),
41+
PythReceiverError::InvalidAccumulatorMessage => write!(f, "InvalidAccumulatorMessage"),
42+
PythReceiverError::InvalidMerkleRoot => write!(f, "InvalidMerkleRoot"),
43+
PythReceiverError::InvalidMerklePath => write!(f, "InvalidMerklePath"),
44+
PythReceiverError::InvalidUnknownSource => write!(f, "InvalidUnknownSource"),
45+
PythReceiverError::NewPriceUnavailable => write!(f, "NewPriceUnavailable"),
46+
PythReceiverError::InvalidAccumulatorMessageType => write!(f, "InvalidAccumulatorMessageType"),
47+
PythReceiverError::InsufficientFee => write!(f, "InsufficientFee"),
48+
PythReceiverError::InvalidEmitterAddress => write!(f, "InvalidEmitterAddress"),
49+
PythReceiverError::TooManyUpdates => write!(f, "TooManyUpdates"),
50+
PythReceiverError::PriceFeedNotFoundWithinRange => write!(f, "PriceFeedNotFoundWithinRange"),
51+
PythReceiverError::NoFreshUpdate => write!(f, "NoFreshUpdate"),
52+
PythReceiverError::PriceFeedNotFound => write!(f, "PriceFeedNotFound"),
53+
PythReceiverError::InvalidGovernanceMessage => write!(f, "InvalidGovernanceMessage"),
54+
PythReceiverError::InvalidGovernanceTarget => write!(f, "InvalidGovernanceTarget"),
55+
PythReceiverError::InvalidGovernanceAction => write!(f, "InvalidGovernanceAction"),
56+
PythReceiverError::InvalidGovernanceDataSource => write!(f, "InvalidGovernanceDataSource"),
57+
PythReceiverError::OldGovernanceMessage => write!(f, "OldGovernanceMessage"),
58+
PythReceiverError::GovernanceMessageAlreadyExecuted => write!(f, "GovernanceMessageAlreadyExecuted"),
59+
PythReceiverError::InvalidWormholeAddressToSet => write!(f, "InvalidWormholeAddressToSet"),
60+
}
61+
}
62+
}
63+
64+
impl core::fmt::Display for PythReceiverError {
65+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
66+
match self {
67+
PythReceiverError::PriceUnavailable => write!(f, "Price unavailable"),
68+
PythReceiverError::InvalidUpdateData => write!(f, "Invalid update data"),
69+
PythReceiverError::VaaVerificationFailed => write!(f, "VAA verification failed"),
70+
PythReceiverError::InvalidVaa => write!(f, "Invalid VAA"),
71+
PythReceiverError::InvalidWormholeMessage => write!(f, "Invalid Wormhole message"),
72+
PythReceiverError::InvalidMerkleProof => write!(f, "Invalid Merkle proof"),
73+
PythReceiverError::InvalidAccumulatorMessage => write!(f, "Invalid accumulator message"),
74+
PythReceiverError::InvalidMerkleRoot => write!(f, "Invalid Merkle root"),
75+
PythReceiverError::InvalidMerklePath => write!(f, "Invalid Merkle path"),
76+
PythReceiverError::InvalidUnknownSource => write!(f, "Invalid unknown source"),
77+
PythReceiverError::NewPriceUnavailable => write!(f, "New price unavailable"),
78+
PythReceiverError::InvalidAccumulatorMessageType => write!(f, "Invalid accumulator message type"),
79+
PythReceiverError::InsufficientFee => write!(f, "Insufficient fee"),
80+
PythReceiverError::InvalidEmitterAddress => write!(f, "Invalid emitter address"),
81+
PythReceiverError::TooManyUpdates => write!(f, "Too many updates"),
82+
PythReceiverError::PriceFeedNotFoundWithinRange => write!(f, "Price feed not found within range"),
83+
PythReceiverError::NoFreshUpdate => write!(f, "No fresh update"),
84+
PythReceiverError::PriceFeedNotFound => write!(f, "Price feed not found"),
85+
PythReceiverError::InvalidGovernanceMessage => write!(f, "Invalid governance message"),
86+
PythReceiverError::InvalidGovernanceTarget => write!(f, "Invalid governance target"),
87+
PythReceiverError::InvalidGovernanceAction => write!(f, "Invalid governance action"),
88+
PythReceiverError::InvalidGovernanceDataSource => write!(f, "Invalid governance data source"),
89+
PythReceiverError::OldGovernanceMessage => write!(f, "Old governance message"),
90+
PythReceiverError::GovernanceMessageAlreadyExecuted => write!(f, "Governance message already executed"),
91+
PythReceiverError::InvalidWormholeAddressToSet => write!(f, "Invalid Wormhole address to set"),
92+
}
3593
}
3694
}
3795

0 commit comments

Comments
 (0)