Skip to content

Commit

Permalink
chore(iota-indexer): remove IndexerError suffixes (#3306)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Oct 22, 2024
1 parent b509907 commit ee904dd
Show file tree
Hide file tree
Showing 20 changed files with 198 additions and 205 deletions.
4 changes: 2 additions & 2 deletions crates/iota-analytics-indexer/src/handlers/df_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl DynamicFieldHandler {
let name_type = move_object.type_().try_extract_field_name(&type_)?;

let bcs_name = bcs::to_bytes(&name_value.clone().undecorate()).map_err(|e| {
IndexerError::SerdeError(format!(
IndexerError::Serde(format!(
"Failed to serialize dynamic field name {:?}: {e}",
name_value
))
Expand Down Expand Up @@ -166,7 +166,7 @@ impl DynamicFieldHandler {
},
DynamicFieldType::DynamicObject => {
let object = all_written_objects.get(&object_id).ok_or(
IndexerError::UncategorizedError(anyhow::anyhow!(
IndexerError::Uncategorized(anyhow::anyhow!(
"Failed to find object_id {:?} when trying to create dynamic field info",
object_id
)),
Expand Down
8 changes: 4 additions & 4 deletions crates/iota-indexer/src/apis/governance_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<T: R2D2Connection + 'static> GovernanceReadApi<T> {
.await
{
Ok(Some(epoch_info)) => Ok(epoch_info),
Ok(None) => Err(IndexerError::InvalidArgumentError(format!(
Ok(None) => Err(IndexerError::InvalidArgument(format!(
"Missing epoch {epoch:?}"
))),
Err(e) => Err(e),
Expand Down Expand Up @@ -168,7 +168,7 @@ impl<T: R2D2Connection + 'static> GovernanceReadApi<T> {
for (pool_id, stakes) in pools {
// Rate table and rate can be null when the pool is not active
let rate_table = rates.get(&pool_id).ok_or_else(|| {
IndexerError::InvalidArgumentError(format!(
IndexerError::InvalidArgument(format!(
"Cannot find rates for staking pool {pool_id}"
))
})?;
Expand Down Expand Up @@ -226,7 +226,7 @@ impl<T: R2D2Connection + 'static> GovernanceReadApi<T> {
for (pool_id, stakes) in pools {
// Rate table and rate can be null when the pool is not active
let rate_table = rates.get(&pool_id).ok_or_else(|| {
IndexerError::InvalidArgumentError(format!(
IndexerError::InvalidArgument(format!(
"Cannot find rates for staking pool {pool_id}"
))
})?;
Expand Down Expand Up @@ -453,7 +453,7 @@ impl<T: R2D2Connection + 'static> GovernanceReadApiServer for GovernanceReadApi<
let epoch = self.get_epoch_info(None).await?;
Ok(BigInt::from(epoch.reference_gas_price.ok_or_else(
|| {
IndexerError::PersistentStorageDataCorruptionError(
IndexerError::PersistentStorageDataCorruption(
"missing latest reference gas price".to_owned(),
)
},
Expand Down
4 changes: 2 additions & 2 deletions crates/iota-indexer/src/apis/read_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<T: R2D2Connection + 'static> ReadApi<T> {
.await
{
Ok(Some(epoch_info)) => Ok(epoch_info),
Ok(None) => Err(IndexerError::InvalidArgumentError(format!(
Ok(None) => Err(IndexerError::InvalidArgument(format!(
"Checkpoint {id:?} not found"
))),
Err(e) => Err(e),
Expand Down Expand Up @@ -150,7 +150,7 @@ impl<T: R2D2Connection + 'static> ReadApiServer for ReadApi<T> {
.await?;

let txn = txn.pop().ok_or_else(|| {
IndexerError::InvalidArgumentError(format!("Transaction {digest} not found"))
IndexerError::InvalidArgument(format!("Transaction {digest} not found"))
})?;

Ok(txn)
Expand Down
12 changes: 6 additions & 6 deletions crates/iota-indexer/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub fn new_connection_pool_with_config<T: R2D2Connection + 'static>(
.connection_customizer(Box::new(pool_config.connection_config()))
.build(manager)
.map_err(|e| {
IndexerError::PgConnectionPoolInitError(format!(
IndexerError::PgConnectionPoolInit(format!(
"Failed to initialize connection pool for {db_url} with error: {e:?}"
))
})
Expand All @@ -154,7 +154,7 @@ pub fn get_pool_connection<T: R2D2Connection + Send + 'static>(
pool: &ConnectionPool<T>,
) -> Result<PoolConnection<T>, IndexerError> {
pool.get().map_err(|e| {
IndexerError::PgPoolConnectionError(format!(
IndexerError::PgPoolConnection(format!(
"Failed to get connection from PG connection pool with error: {:?}",
e
))
Expand Down Expand Up @@ -276,7 +276,7 @@ pub mod setup_postgres {
registry: Registry,
) -> Result<(), IndexerError> {
let db_url_secret = indexer_config.get_db_url().map_err(|e| {
IndexerError::PgPoolConnectionError(format!(
IndexerError::PgPoolConnection(format!(
"Failed parsing database url with error {:?}",
e
))
Expand Down Expand Up @@ -304,7 +304,7 @@ pub mod setup_postgres {
db_url, e
);
error!("{}", db_err_msg);
IndexerError::PostgresResetError(db_err_msg)
IndexerError::PostgresReset(db_err_msg)
})?;
info!("Reset Postgres database complete.");
}
Expand Down Expand Up @@ -408,7 +408,7 @@ pub mod setup_mysql {
registry: Registry,
) -> Result<(), IndexerError> {
let db_url_secret = indexer_config.get_db_url().map_err(|e| {
IndexerError::PgPoolConnectionError(format!(
IndexerError::PgPoolConnection(format!(
"Failed parsing database url with error {:?}",
e
))
Expand All @@ -433,7 +433,7 @@ pub mod setup_mysql {
db_url, e
);
error!("{}", db_err_msg);
IndexerError::PostgresResetError(db_err_msg)
IndexerError::PostgresReset(db_err_msg)
})?;
info!("Reset MySQL database complete.");
}
Expand Down
66 changes: 33 additions & 33 deletions crates/iota-indexer/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,108 +31,108 @@ impl std::fmt::Display for DataDownloadError {
#[non_exhaustive]
pub enum IndexerError {
#[error("Indexer failed to convert timestamp to NaiveDateTime with error: `{0}`")]
DateTimeParsingError(String),
DateTimeParsing(String),

#[error("Indexer failed to deserialize event from events table with error: `{0}`")]
EventDeserializationError(String),
EventDeserialization(String),

#[error(
"Fullnode returns unexpected responses, which may block indexers from proceeding, with error: `{0}`"
)]
UnexpectedFullnodeResponseError(String),
UnexpectedFullnodeResponse(String),

#[error("Indexer failed to transform data with error: `{0}`")]
DataTransformationError(String),
DataTransformation(String),

#[error("Indexer failed to read fullnode with error: `{0}`")]
FullNodeReadingError(String),
FullNodeReading(String),

#[error("Indexer failed to convert structs to diesel Insertable with error: `{0}`")]
InsertableParsingError(String),
InsertableParsing(String),

#[error("Indexer failed to build JsonRpcServer with error: `{0}`")]
JsonRpcServerError(#[from] iota_json_rpc::error::Error),
JsonRpcServer(#[from] iota_json_rpc::error::Error),

#[error("Indexer failed to find object mutations, which should never happen.")]
ObjectMutationNotAvailable,

#[error("Indexer failed to build PG connection pool with error: `{0}`")]
PgConnectionPoolInitError(String),
PgConnectionPoolInit(String),

#[error("Indexer failed to get a pool connection from PG connection pool with error: `{0}`")]
PgPoolConnectionError(String),
PgPoolConnection(String),

#[error("Indexer failed to read PostgresDB with error: `{0}`")]
PostgresReadError(String),
PostgresRead(String),

#[error("Indexer failed to reset PostgresDB with error: `{0}`")]
PostgresResetError(String),
PostgresReset(String),

#[error("Indexer failed to commit changes to PostgresDB with error: `{0}`")]
PostgresWriteError(String),
PostgresWrite(String),

#[error(transparent)]
PostgresError(#[from] diesel::result::Error),
Postgres(#[from] diesel::result::Error),

#[error("Indexer failed to initialize fullnode Http client with error: `{0}`")]
HttpClientInitError(String),
HttpClientInit(String),

#[error("Indexer failed to serialize/deserialize with error: `{0}`")]
SerdeError(String),
Serde(String),

#[error("Indexer error related to dynamic field: `{0}`")]
DynamicFieldError(String),
DynamicField(String),

#[error("Indexer does not support the feature with error: `{0}`")]
NotSupportedError(String),
NotSupported(String),

#[error("Indexer read corrupted/incompatible data from persistent storage: `{0}`")]
PersistentStorageDataCorruptionError(String),
PersistentStorageDataCorruption(String),

#[error("Indexer generic error: `{0}`")]
GenericError(String),
Generic(String),

#[error("Indexer failed to resolve object to move struct with error: `{0}`")]
ResolveMoveStructError(String),
ResolveMoveStruct(String),

#[error(transparent)]
UncategorizedError(#[from] anyhow::Error),
Uncategorized(#[from] anyhow::Error),

#[error(transparent)]
ObjectIdParseError(#[from] ObjectIDParseError),
ObjectIdParse(#[from] ObjectIDParseError),

#[error("Invalid transaction digest with error: `{0}`")]
InvalidTransactionDigestError(String),
InvalidTransactionDigest(String),

#[error(transparent)]
IotaError(#[from] IotaError),
Iota(#[from] IotaError),

#[error(transparent)]
BcsError(#[from] bcs::Error),
Bcs(#[from] bcs::Error),

#[error("Invalid argument with error: `{0}`")]
InvalidArgumentError(String),
InvalidArgument(String),

#[error(transparent)]
UserInputError(#[from] UserInputError),
UserInput(#[from] UserInputError),

#[error("Indexer failed to resolve module with error: `{0}`")]
ModuleResolutionError(String),
ModuleResolution(String),

#[error(transparent)]
ObjectResponseError(#[from] IotaObjectResponseError),
ObjectResponse(#[from] IotaObjectResponseError),

#[error(transparent)]
FastCryptoError(#[from] FastCryptoError),
FastCrypto(#[from] FastCryptoError),

#[error("`{0}`: `{1}`")]
ErrorWithContext(String, Box<IndexerError>),

#[error("Indexer failed to send item to channel with error: `{0}`")]
MpscChannelError(String),
MpscChannel(String),

#[error("Failed to process checkpoint(s): `{0}`")]
CheckpointProcessingError(String),
CheckpointProcessing(String),
}

pub trait Context<T> {
Expand All @@ -159,6 +159,6 @@ impl From<IndexerError> for ErrorObjectOwned {

impl From<tokio::task::JoinError> for IndexerError {
fn from(value: tokio::task::JoinError) -> Self {
IndexerError::UncategorizedError(anyhow::Error::from(value))
IndexerError::Uncategorized(anyhow::Error::from(value))
}
}
16 changes: 8 additions & 8 deletions crates/iota-indexer/src/handlers/checkpoint_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ where
.map(|(seq, execution_digest)| (execution_digest.transaction, seq));

if checkpoint_contents.size() != transactions.len() {
return Err(IndexerError::FullNodeReadingError(format!(
return Err(IndexerError::FullNodeReading(format!(
"CheckpointContents has different size {} compared to Transactions {} for checkpoint {}",
checkpoint_contents.size(),
transactions.len(),
Expand All @@ -398,7 +398,7 @@ where
// Unwrap safe - we checked they have equal length above
let (tx_digest, tx_sequence_number) = tx_seq_num_iter.next().unwrap();
if tx_digest != *sender_signed_data.digest() {
return Err(IndexerError::FullNodeReadingError(format!(
return Err(IndexerError::FullNodeReading(format!(
"Transactions has different ordering from CheckpointContents, for checkpoint {}, Mismatch found at {} v.s. {}",
checkpoint_seq,
tx_digest,
Expand Down Expand Up @@ -692,7 +692,7 @@ where
if let Some(pg_state) = state_as_any.downcast_ref::<PgIndexerStore<T>>() {
return Ok(pg_state.blocking_cp());
}
Err(IndexerError::UncategorizedError(anyhow::anyhow!(
Err(IndexerError::Uncategorized(anyhow::anyhow!(
"Failed to downcast state to PgIndexerStore"
)))
}
Expand Down Expand Up @@ -726,14 +726,14 @@ async fn get_move_struct_layout_map(
.type_layout(TypeTag::Struct(Box::new(struct_tag.clone())))
.await
.map_err(|e| {
IndexerError::DynamicFieldError(format!(
IndexerError::DynamicField(format!(
"Fail to resolve struct layout for {:?} with {:?}.",
struct_tag, e
))
})?;
let move_struct_layout = match move_type_layout {
MoveTypeLayout::Struct(s) => Ok(s),
_ => Err(IndexerError::ResolveMoveStructError(
_ => Err(IndexerError::ResolveMoveStruct(
"MoveTypeLayout is not Struct".to_string(),
)),
}?;
Expand Down Expand Up @@ -773,7 +773,7 @@ fn try_create_dynamic_field_info(
.get(&struct_tag)
.cloned()
.ok_or_else(|| {
IndexerError::DynamicFieldError(format!(
IndexerError::DynamicField(format!(
"Cannot find struct layout in mapfor {:?}.",
struct_tag
))
Expand All @@ -783,7 +783,7 @@ fn try_create_dynamic_field_info(
DynamicFieldInfo::parse_move_object(&move_struct).tap_err(|e| warn!("{e}"))?;
let name_type = move_object.type_().try_extract_field_name(&type_)?;
let bcs_name = bcs::to_bytes(&name_value.clone().undecorate()).map_err(|e| {
IndexerError::SerdeError(format!(
IndexerError::Serde(format!(
"Failed to serialize dynamic field name {:?}: {e}",
name_value
))
Expand All @@ -796,7 +796,7 @@ fn try_create_dynamic_field_info(
DynamicFieldType::DynamicObject => {
let object = latest_objects
.get(&object_id)
.ok_or(IndexerError::UncategorizedError(anyhow::anyhow!(
.ok_or(IndexerError::Uncategorized(anyhow::anyhow!(
"Failed to find object_id {:?} when trying to create dynamic field info",
object_id
)))?;
Expand Down
Loading

0 comments on commit ee904dd

Please sign in to comment.