Skip to content

Commit

Permalink
refactor: be consistent naming errors in client and protos
Browse files Browse the repository at this point in the history
  • Loading branch information
suchapalaver committed Nov 26, 2024
1 parent 53c11e4 commit c9bdd47
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 93 deletions.
12 changes: 6 additions & 6 deletions crates/firehose-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use thiserror::Error;

#[derive(Debug, Error)]
pub enum ClientError {
#[error("Missing environment variable: {0}")]
EnvVarMissing(#[from] dotenvy::Error),

#[error("gRPC error: {0}")]
GRpc(#[from] tonic::transport::Error),

#[error("Invalid URI: {0}")]
InvalidUri(#[from] InvalidUri),

#[error("Missing environment variable: {0}")]
MissingEnvVar(#[from] dotenvy::Error),

#[error("{0}")]
TonicStatus(#[from] tonic::Status),

#[error("Invalid URI: {0}")]
UriInvalid(#[from] InvalidUri),
}
118 changes: 59 additions & 59 deletions crates/firehose-protos/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +3,85 @@ use thiserror::Error;
/// Custom error variants for Verifiable Extraction protobuffer types.
#[derive(Error, Debug)]
pub enum ProtosError {
/// Error converting protobuffer to block type.
#[error("Block conversion error")]
BlockConversionError,

/// [BLS signature](https://en.wikipedia.org/wiki/BLS_digital_signature) error.
#[error("BLS error: {0}")]
Bls(String),

/// [prost] library decode error.
#[error("Error in decoding block: {0}")]
DecodeError(#[from] prost::DecodeError),

/// Graffiti invalid when decoding block.
#[error("GraffitiInvalid")]
GraffitiInvalid,

/// Invalid access tuple storage key.
#[error("Invalid access tuple storage key: {0}")]
InvalidAccessTupleStorageKey(String),
AccessTupleStorageKeyInvalid(String),

/// Missing attestation data.
#[error("Null attestation data")]
AttestationDataMissing,

/// Invalid BigInt.
#[error("Invalid BigInt: {0}")]
InvalidBigInt(String),
BigIntInvalid(String),

/// Invalid log address.
#[error("Invalid log address: {0}")]
InvalidLogAddress(String),

/// Invalid log topic.
#[error("Invalid log topic: {0}")]
InvalidLogTopic(String),

/// Invalid trace signature for ECDSA component.
#[error("Invalid trace signature {0:?} component: {1}")]
InvalidTraceSignature(String, String),

/// Invalid transaction receipt logs bloom.
#[error("Invalid transaction receipt logs bloom: {0}")]
InvalidTransactionReceiptLogsBloom(String),

/// Invalid KZG commitment.
#[error("KzgCommitmentInvalid")]
KzgCommitmentInvalid,
/// Error converting protobuffer to block type.
#[error("Block conversion error")]
BlockConversionError,

/// Converted block missing block header.
#[error("MissingBlockHeader")]
MissingBlockHeader,

/// Missing attestation data.
#[error("Null attestation data")]
NullAttestationData,

/// Missing indexed attestation data.
#[error("Null indexed attestation data")]
NullIndexedAttestationData,
#[error("BlockHeaderMissing")]
BlockHeaderMissing,

/// Block response missing block.
#[error("Null block field in block response")]
NullBlock,
BlockMissingInResponse,

/// [BLS signature](https://en.wikipedia.org/wiki/BLS_digital_signature) error.
#[error("BLS error: {0}")]
Bls(String),

/// Missing BLS to Execution Change
#[error("Null BlsToExecutionChange")]
NullBlsToExecutionChange,
BlsToExecutionChangeMissing,

/// Checkpoint missing.
#[error("Null checkpoint")]
NullCheckpoint,
CheckpointMissing,

/// [prost] library decode error.
#[error("Error in decoding block: {0}")]
DecodeError(#[from] prost::DecodeError),

/// Missing deposit data.
#[error("Null deposit data")]
NullDepositData,
DepositDataMissing,

/// Missing execution payload.
#[error("Null execution payload")]
NullExecutionPayload,
ExecutionPayloadMissing,

/// Missing signer
#[error("Null signer")]
NullSigner,
/// Graffiti invalid when decoding block.
#[error("GraffitiInvalid")]
GraffitiInvalid,

/// Missing indexed attestation data.
#[error("Null indexed attestation data")]
IndexedAttestationDataMissing,

/// Invalid KZG commitment.
#[error("KzgCommitmentInvalid")]
KzgCommitmentInvalid,

/// Invalid log address.
#[error("Invalid log address: {0}")]
LogAddressInvalid(String),

/// Invalid log topic.
#[error("Invalid log topic: {0}")]
LogTopicInvalid(String),

/// Missing signed Beacon block header message.
#[error("Null SignedBeaconBlockHeader Message")]
NullSignedBeaconBlockHeaderMessage,
SignedBeaconBlockHeaderMessageMissing,

/// Missing voluntary exit.
#[error("Null voluntary exit")]
NullVoluntaryExit,
/// Missing signer
#[error("Null signer")]
SignerMissing,

/// Invalid trace signature for ECDSA component.
#[error("Invalid trace signature {0:?} component: {1}")]
TraceSignatureInvalid(String, String),

/// SSZ Types error.
#[error("SSZ Types error: {0}")]
Expand All @@ -99,11 +91,19 @@ pub enum ProtosError {
#[error("Transaction missing call")]
TransactionMissingCall,

/// Invalid transaction receipt logs bloom.
#[error("Invalid transaction receipt logs bloom: {0}")]
TransactionReceiptLogsBloomInvalid(String),

/// Transaction trace missing receipt.
#[error("Transaction trace missing receipt")]
TransactionTraceMissingReceipt,

/// Transaction type conversion error.
#[error("TxTypeConversionError: {0}")]
TxTypeConversion(String),

/// Missing voluntary exit.
#[error("Null voluntary exit")]
VoluntaryExitMissing,
}
4 changes: 2 additions & 2 deletions crates/firehose-protos/src/ethereum_v2/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn convert_to_b256(key: &Vec<u8>) -> Result<B256, ProtosError> {
let key_bytes: [u8; 32] = key
.as_slice()
.try_into()
.map_err(|_| ProtosError::InvalidAccessTupleStorageKey(hex::encode(key.clone())))?;
.map_err(|_| ProtosError::AccessTupleStorageKeyInvalid(hex::encode(key.clone())))?;
Ok(B256::from(key_bytes))
}

Expand Down Expand Up @@ -80,7 +80,7 @@ mod tests {

assert!(matches!(
error,
ProtosError::InvalidAccessTupleStorageKey(_)
ProtosError::AccessTupleStorageKeyInvalid(_)
));
}
}
6 changes: 3 additions & 3 deletions crates/firehose-protos/src/ethereum_v2/eth_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn decode_block<M>(response: M) -> Result<Block, ProtosError>
where
M: MessageWithBlock,
{
let any = response.block().ok_or(ProtosError::NullBlock)?;
let any = response.block().ok_or(ProtosError::BlockMissingInResponse)?;
let block = Block::decode(any.value.as_ref())?;
Ok(block)
}
Expand Down Expand Up @@ -200,7 +200,7 @@ impl Block {

/// Returns a reference to the block header.
pub fn header(&self) -> Result<&BlockHeader, ProtosError> {
self.header.as_ref().ok_or(ProtosError::MissingBlockHeader)
self.header.as_ref().ok_or(ProtosError::BlockHeaderMissing)
}

fn is_pre_byzantium(&self) -> bool {
Expand Down Expand Up @@ -310,7 +310,7 @@ impl TryFrom<&TransactionReceipt> for Bloom {
logs_bloom
.try_into()
.map(|array: [u8; BLOOM_SIZE]| Bloom(FixedBytes(array)))
.map_err(|_| Self::Error::InvalidTransactionReceiptLogsBloom(hex::encode(logs_bloom)))
.map_err(|_| Self::Error::TransactionReceiptLogsBloomInvalid(hex::encode(logs_bloom)))
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/firehose-protos/src/ethereum_v2/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ impl TryFrom<&Log> for Address {
.address
.as_slice()
.try_into()
.map_err(|_| Self::Error::InvalidLogAddress(hex::encode(log.address.clone())))?;
.map_err(|_| Self::Error::LogAddressInvalid(hex::encode(log.address.clone())))?;
Ok(Address::from(slice))
}
}

impl Log {
fn to_topics(&self) -> Result<Vec<B256>, ProtosError> {
fn to_b256(slice: &[u8]) -> Result<B256, ProtosError> {
B256::try_from(slice).map_err(|_| ProtosError::InvalidLogTopic(hex::encode(slice)))
B256::try_from(slice).map_err(|_| ProtosError::LogTopicInvalid(hex::encode(slice)))
}

self.topics
Expand Down Expand Up @@ -105,7 +105,7 @@ mod tests {

let error = Address::try_from(&fake_log).unwrap_err();

assert!(matches!(error, ProtosError::InvalidLogAddress(_)));
assert!(matches!(error, ProtosError::LogAddressInvalid(_)));
}

#[test]
Expand All @@ -114,7 +114,7 @@ mod tests {

let error = fake_log.to_topics().unwrap_err();

assert!(matches!(error, ProtosError::InvalidLogTopic(_)));
assert!(matches!(error, ProtosError::LogTopicInvalid(_)));
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions crates/firehose-protos/src/ethereum_v2/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl TransactionTrace {

// If V is outside the expected range, return an error.
_ => {
return Err(ProtosError::InvalidTraceSignature(
return Err(ProtosError::TraceSignatureInvalid(
EcdsaComponent::V.to_string(),
v.to_string(),
))
Expand Down Expand Up @@ -149,13 +149,13 @@ impl TryFrom<&TransactionTrace> for Signature {

// Extract the R value from the trace and ensure it's a valid 32-byte array.
let r_bytes: [u8; 32] = trace.r.as_slice().try_into().map_err(|_| {
Self::Error::InvalidTraceSignature(R.to_string(), hex::encode(&trace.r))
Self::Error::TraceSignatureInvalid(R.to_string(), hex::encode(&trace.r))
})?;
let r = U256::from_be_bytes(r_bytes);

// Extract the S value from the trace and ensure it's a valid 32-byte array.
let s_bytes: [u8; 32] = trace.s.as_slice().try_into().map_err(|_| {
Self::Error::InvalidTraceSignature(S.to_string(), hex::encode(&trace.s))
Self::Error::TraceSignatureInvalid(S.to_string(), hex::encode(&trace.s))
})?;
let s = U256::from_be_bytes(s_bytes);

Expand Down Expand Up @@ -272,7 +272,7 @@ impl TryFrom<&BigInt> for u128 {
fn try_from(value: &BigInt) -> Result<Self, Self::Error> {
let slice = value.bytes.as_slice();
let n =
U128::try_from_be_slice(slice).ok_or(ProtosError::InvalidBigInt(hex::encode(slice)))?;
U128::try_from_be_slice(slice).ok_or(ProtosError::BigIntInvalid(hex::encode(slice)))?;
Ok(u128::from_le_bytes(n.to_le_bytes()))
}
}
Expand Down
Loading

0 comments on commit c9bdd47

Please sign in to comment.