diff --git a/crates/iota-analytics-indexer/src/handlers/df_handler.rs b/crates/iota-analytics-indexer/src/handlers/df_handler.rs index e3bab5d4ee2..cebe8cd6ef5 100644 --- a/crates/iota-analytics-indexer/src/handlers/df_handler.rs +++ b/crates/iota-analytics-indexer/src/handlers/df_handler.rs @@ -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 )) @@ -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 )), diff --git a/crates/iota-indexer/src/apis/governance_api.rs b/crates/iota-indexer/src/apis/governance_api.rs index d1feb502b97..d697288cfdb 100644 --- a/crates/iota-indexer/src/apis/governance_api.rs +++ b/crates/iota-indexer/src/apis/governance_api.rs @@ -67,7 +67,7 @@ impl GovernanceReadApi { .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), @@ -168,7 +168,7 @@ impl GovernanceReadApi { 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}" )) })?; @@ -226,7 +226,7 @@ impl GovernanceReadApi { 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}" )) })?; @@ -453,7 +453,7 @@ impl 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(), ) }, diff --git a/crates/iota-indexer/src/apis/read_api.rs b/crates/iota-indexer/src/apis/read_api.rs index 8fc8ffaba9a..15b35ecc24a 100644 --- a/crates/iota-indexer/src/apis/read_api.rs +++ b/crates/iota-indexer/src/apis/read_api.rs @@ -41,7 +41,7 @@ impl ReadApi { .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), @@ -150,7 +150,7 @@ impl ReadApiServer for ReadApi { .await?; let txn = txn.pop().ok_or_else(|| { - IndexerError::InvalidArgumentError(format!("Transaction {digest} not found")) + IndexerError::InvalidArgument(format!("Transaction {digest} not found")) })?; Ok(txn) diff --git a/crates/iota-indexer/src/db.rs b/crates/iota-indexer/src/db.rs index a93039fc5d1..bf93fbbe4a1 100644 --- a/crates/iota-indexer/src/db.rs +++ b/crates/iota-indexer/src/db.rs @@ -144,7 +144,7 @@ pub fn new_connection_pool_with_config( .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:?}" )) }) @@ -154,7 +154,7 @@ pub fn get_pool_connection( pool: &ConnectionPool, ) -> Result, IndexerError> { pool.get().map_err(|e| { - IndexerError::PgPoolConnectionError(format!( + IndexerError::PgPoolConnection(format!( "Failed to get connection from PG connection pool with error: {:?}", e )) @@ -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 )) @@ -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."); } @@ -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 )) @@ -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."); } diff --git a/crates/iota-indexer/src/errors.rs b/crates/iota-indexer/src/errors.rs index 08e0b9d00d1..406762acea2 100644 --- a/crates/iota-indexer/src/errors.rs +++ b/crates/iota-indexer/src/errors.rs @@ -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), #[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 { @@ -159,6 +159,6 @@ impl From for ErrorObjectOwned { impl From for IndexerError { fn from(value: tokio::task::JoinError) -> Self { - IndexerError::UncategorizedError(anyhow::Error::from(value)) + IndexerError::Uncategorized(anyhow::Error::from(value)) } } diff --git a/crates/iota-indexer/src/handlers/checkpoint_handler.rs b/crates/iota-indexer/src/handlers/checkpoint_handler.rs index a17c57b3601..d6a7255322e 100644 --- a/crates/iota-indexer/src/handlers/checkpoint_handler.rs +++ b/crates/iota-indexer/src/handlers/checkpoint_handler.rs @@ -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(), @@ -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, @@ -692,7 +692,7 @@ where if let Some(pg_state) = state_as_any.downcast_ref::>() { return Ok(pg_state.blocking_cp()); } - Err(IndexerError::UncategorizedError(anyhow::anyhow!( + Err(IndexerError::Uncategorized(anyhow::anyhow!( "Failed to downcast state to PgIndexerStore" ))) } @@ -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(), )), }?; @@ -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 )) @@ -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 )) @@ -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 )))?; diff --git a/crates/iota-indexer/src/indexer_reader.rs b/crates/iota-indexer/src/indexer_reader.rs index 70f94b7e9b5..7f98bc442be 100644 --- a/crates/iota-indexer/src/indexer_reader.rs +++ b/crates/iota-indexer/src/indexer_reader.rs @@ -235,7 +235,7 @@ impl IndexerReader { .fetch(package_id.into()) .await .map_err(|e| { - IndexerError::PostgresReadError(format!( + IndexerError::PostgresRead(format!( "Fail to fetch package from package store with error {:?}", e )) @@ -349,12 +349,12 @@ impl IndexerReader { let stored_epoch = self.get_epoch_info_from_db(epoch)?; let stored_epoch = match stored_epoch { Some(stored_epoch) => stored_epoch, - None => return Err(IndexerError::InvalidArgumentError("Invalid epoch".into())), + None => return Err(IndexerError::InvalidArgument("Invalid epoch".into())), }; let system_state: IotaSystemStateSummary = bcs::from_bytes(&stored_epoch.system_state) .map_err(|_| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Failed to deserialize `system_state` for epoch {:?}", epoch, )) @@ -623,7 +623,7 @@ impl IndexerReader { .as_str(); } } else { - return Err(IndexerError::InvalidArgumentError( + return Err(IndexerError::InvalidArgument( "Invalid filter type. Only struct, MatchAny and MatchNone of struct filters are supported.".into(), )); } @@ -640,14 +640,14 @@ impl IndexerReader { objects::object_type.not_like(format!("{}%", object_type)), ); } else { - return Err(IndexerError::InvalidArgumentError( + return Err(IndexerError::InvalidArgument( "Invalid filter type. Only struct, MatchAny and MatchNone of struct filters are supported.".into(), )); } } } _ => { - return Err(IndexerError::InvalidArgumentError( + return Err(IndexerError::InvalidArgument( "Invalid filter type. Only struct, MatchAny and MatchNone of struct filters are supported.".into(), )); } @@ -660,7 +660,7 @@ impl IndexerReader { query .load::(conn) - .map_err(|e| IndexerError::PostgresReadError(e.to_string())) + .map_err(|e| IndexerError::PostgresRead(e.to_string())) }) } @@ -682,7 +682,7 @@ impl IndexerReader { .into_iter() .map(|id| { ObjectID::from_bytes(id.clone()).map_err(|_e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Can't convert {:?} to ObjectID", id, )) @@ -830,7 +830,7 @@ impl IndexerReader { ), ), (None, Some(_)) => { - return Err(IndexerError::InvalidArgumentError( + return Err(IndexerError::InvalidArgument( "Function cannot be present without Module.".into(), )); } @@ -938,7 +938,7 @@ impl IndexerReader { Some( TransactionFilter::TransactionKind(_) | TransactionFilter::TransactionKindIn(_), ) => { - return Err(IndexerError::NotSupportedError( + return Err(IndexerError::NotSupported( "TransactionKind filter is not supported.".into(), )); } @@ -1043,7 +1043,7 @@ impl IndexerReader { ) -> IndexerResult { let cursor = if let Some(cursor) = cursor { if cursor.tx_digest != tx_digest { - return Err(IndexerError::InvalidArgumentError( + return Err(IndexerError::InvalidArgument( "Cursor tx_digest does not match the tx_digest in the query.".into(), )); } @@ -1178,7 +1178,7 @@ impl IndexerReader { | EventFilter::And(_, _) | EventFilter::Or(_, _) | EventFilter::TimeRange { .. } => { - return Err(IndexerError::NotSupportedError( + return Err(IndexerError::NotSupported( "This type of EventFilter is not supported.".into(), )); } @@ -1247,7 +1247,7 @@ impl IndexerReader { .await?; if any(objects.iter(), |o| o.df_object_id.is_none()) { - return Err(IndexerError::PersistentStorageDataCorruptionError(format!( + return Err(IndexerError::PersistentStorageDataCorruption(format!( "Dynamic field has empty df_object_id column for parent object {}", parent_object_id ))); @@ -1340,7 +1340,7 @@ impl IndexerReader { .type_layout(name.type_.clone()) .await .map_err(|e| { - IndexerError::ResolveMoveStructError(format!( + IndexerError::ResolveMoveStruct(format!( "Failed to get type layout for type {}: {}", name.type_, e )) @@ -1368,7 +1368,7 @@ impl IndexerReader { .into_iter() .map(|object_ref: ObjectRefColumn| { let object_id = ObjectID::from_bytes(object_ref.object_id.clone()).map_err(|_e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Can't convert {:?} to ObjectID", object_ref.object_id )) @@ -1376,7 +1376,7 @@ impl IndexerReader { let seq = SequenceNumber::from_u64(object_ref.object_version as u64); let object_digest = ObjectDigest::try_from(object_ref.object_digest.as_slice()) .map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "object {:?} has incompatible object digest. Error: {e}", object_ref.object_digest )) @@ -1625,7 +1625,7 @@ impl IndexerReader { ) -> Result { let (object_type, layout) = if let Some((object_type, layout)) = iota_json_rpc::read_api::get_object_type_and_struct(original_object, original_layout) - .map_err(|e| IndexerError::GenericError(e.to_string()))? + .map_err(|e| IndexerError::Generic(e.to_string()))? { (object_type, layout) } else { @@ -1637,7 +1637,7 @@ impl IndexerReader { if let Some(display_object) = self.get_display_object_by_type(&object_type).await? { return iota_json_rpc::read_api::get_rendered_fields(display_object.fields, &layout) - .map_err(|e| IndexerError::GenericError(e.to_string())); + .map_err(|e| IndexerError::Generic(e.to_string())); } Ok(DisplayFieldsResponse { data: None, @@ -1696,13 +1696,13 @@ impl IndexerReader { get_single_obj_id_from_package_publish(self, package_id, treasury_cap_type.clone()) .unwrap() }) - .ok_or(IndexerError::GenericError(format!( + .ok_or(IndexerError::Generic(format!( "Cannot find treasury cap for type {}", treasury_cap_type )))?; let treasury_cap_obj_object = self.get_object(&treasury_cap_obj_id, None)? - .ok_or(IndexerError::GenericError(format!( + .ok_or(IndexerError::Generic(format!( "Cannot find treasury cap object with id {}", treasury_cap_obj_id )))?; diff --git a/crates/iota-indexer/src/lib.rs b/crates/iota-indexer/src/lib.rs index 494fe0563bc..4593d1b75f2 100644 --- a/crates/iota-indexer/src/lib.rs +++ b/crates/iota-indexer/src/lib.rs @@ -215,7 +215,7 @@ fn get_http_client(rpc_client_url: &str) -> Result { .build(rpc_client_url) .map_err(|e| { warn!("Failed to get new Http client with error: {:?}", e); - IndexerError::HttpClientInitError(format!( + IndexerError::HttpClientInit(format!( "Failed to initialize fullnode RPC client with error: {:?}", e )) diff --git a/crates/iota-indexer/src/models/checkpoints.rs b/crates/iota-indexer/src/models/checkpoints.rs index a11233c93b4..b2bca102061 100644 --- a/crates/iota-indexer/src/models/checkpoints.rs +++ b/crates/iota-indexer/src/models/checkpoints.rs @@ -96,7 +96,7 @@ impl TryFrom for RpcCheckpoint { fn try_from(checkpoint: StoredCheckpoint) -> Result { let parsed_digest = CheckpointDigest::try_from(checkpoint.checkpoint_digest.clone()) .map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Failed to decode checkpoint digest: {:?} with err: {:?}", checkpoint.checkpoint_digest, e )) @@ -106,7 +106,7 @@ impl TryFrom for RpcCheckpoint { .previous_checkpoint_digest .map(|digest| { CheckpointDigest::try_from(digest.clone()).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Failed to decode previous checkpoint digest: {:?} with err: {:?}", digest, e )) @@ -121,12 +121,12 @@ impl TryFrom for RpcCheckpoint { .tx_digests .into_iter() .map(|tx_digest| match tx_digest { - None => Err(IndexerError::PersistentStorageDataCorruptionError( + None => Err(IndexerError::PersistentStorageDataCorruption( "tx_digests should not contain null elements".to_string(), )), Some(tx_digest) => TransactionDigest::try_from(tx_digest.as_slice()) .map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Failed to decode transaction digest: {:?} with err: {:?}", tx_digest, e )) @@ -141,26 +141,26 @@ impl TryFrom for RpcCheckpoint { .tx_digests .as_array() .ok_or_else(|| { - IndexerError::PersistentStorageDataCorruptionError( + IndexerError::PersistentStorageDataCorruption( "Failed to parse tx_digests as array".to_string(), ) })? .iter() .map(|tx_digest| match tx_digest { serde_json::Value::Null => { - Err(IndexerError::PersistentStorageDataCorruptionError( + Err(IndexerError::PersistentStorageDataCorruption( "tx_digests should not contain null elements".to_string(), )) } serde_json::Value::String(tx_digest) => { TransactionDigest::try_from(tx_digest.as_bytes()).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Failed to decode transaction digest: {:?} with err: {:?}", tx_digest, e )) }) } - _ => Err(IndexerError::PersistentStorageDataCorruptionError( + _ => Err(IndexerError::PersistentStorageDataCorruption( "tx_digests should contain only string elements".to_string(), )), }) @@ -169,7 +169,7 @@ impl TryFrom for RpcCheckpoint { }; let validator_signature = bcs::from_bytes(&checkpoint.validator_signature).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Failed to decode validator signature: {:?} with err: {:?}", checkpoint.validator_signature, e )) @@ -177,7 +177,7 @@ impl TryFrom for RpcCheckpoint { let checkpoint_commitments = bcs::from_bytes(&checkpoint.checkpoint_commitments).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Failed to decode checkpoint commitments: {:?} with err: {:?}", checkpoint.checkpoint_commitments, e )) @@ -187,7 +187,7 @@ impl TryFrom for RpcCheckpoint { .end_of_epoch_data .map(|data| { bcs::from_bytes(&data).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Failed to decode end of epoch data: {:?} with err: {:?}", data, e )) diff --git a/crates/iota-indexer/src/models/epoch.rs b/crates/iota-indexer/src/models/epoch.rs index 657c228a908..ade16036ca5 100644 --- a/crates/iota-indexer/src/models/epoch.rs +++ b/crates/iota-indexer/src/models/epoch.rs @@ -157,7 +157,7 @@ impl TryFrom for EpochInfo { let end_of_epoch_info = (&value).into(); let system_state: Option = bcs::from_bytes(&value.system_state) .map_err(|_| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Failed to deserialize `system_state` for epoch {epoch}", )) }) diff --git a/crates/iota-indexer/src/models/events.rs b/crates/iota-indexer/src/models/events.rs index 3c4fe0ac51d..948f8621339 100644 --- a/crates/iota-indexer/src/models/events.rs +++ b/crates/iota-indexer/src/models/events.rs @@ -92,7 +92,7 @@ impl StoredEvent { package_resolver: Arc>, ) -> Result { let package_id = ObjectID::from_bytes(self.package.clone()).map_err(|_e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Failed to parse event package ID: {:?}", self.package )) @@ -102,7 +102,7 @@ impl StoredEvent { #[cfg(feature = "postgres-feature")] { self.senders.first().ok_or_else(|| { - IndexerError::PersistentStorageDataCorruptionError( + IndexerError::PersistentStorageDataCorruption( "Event senders should contain at least one address".to_string(), ) })? @@ -113,13 +113,13 @@ impl StoredEvent { self.senders .as_array() .ok_or_else(|| { - IndexerError::PersistentStorageDataCorruptionError( + IndexerError::PersistentStorageDataCorruption( "Failed to parse event senders as array".to_string(), ) })? .first() .ok_or_else(|| { - IndexerError::PersistentStorageDataCorruptionError( + IndexerError::PersistentStorageDataCorruption( "Event senders should contain at least one address".to_string(), ) })? @@ -129,13 +129,13 @@ impl StoredEvent { }; let sender = match sender { Some(ref s) => IotaAddress::from_bytes(s).map_err(|_e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Failed to parse event sender address: {:?}", sender )) })?, None => { - return Err(IndexerError::PersistentStorageDataCorruptionError( + return Err(IndexerError::PersistentStorageDataCorruption( "Event senders element should not be null".to_string(), )); } @@ -146,17 +146,17 @@ impl StoredEvent { .type_layout(type_.clone().into()) .await .map_err(|e| { - IndexerError::ResolveMoveStructError(format!( + IndexerError::ResolveMoveStruct(format!( "Failed to convert to iota event with Error: {e}", )) })?; let move_object = BoundedVisitor::deserialize_value(&self.bcs, &move_type_layout) - .map_err(|e| IndexerError::SerdeError(e.to_string()))?; + .map_err(|e| IndexerError::Serde(e.to_string()))?; let (_, parsed_json) = type_and_fields_from_move_event_data(move_object) - .map_err(|e| IndexerError::SerdeError(e.to_string()))?; + .map_err(|e| IndexerError::Serde(e.to_string()))?; let tx_digest = TransactionDigest::try_from(self.transaction_digest.as_slice()).map_err(|e| { - IndexerError::SerdeError(format!( + IndexerError::Serde(format!( "Failed to parse transaction digest: {:?}, error: {}", self.transaction_digest, e )) diff --git a/crates/iota-indexer/src/models/large_objects.rs b/crates/iota-indexer/src/models/large_objects.rs index 704083e6d1d..e5f179e1ba6 100644 --- a/crates/iota-indexer/src/models/large_objects.rs +++ b/crates/iota-indexer/src/models/large_objects.rs @@ -71,7 +71,7 @@ pub fn put_large_object_in_chunks( let oid = create_large_object(pool)?; if let Err(err) = i64::try_from(data.len()) { - return Err(IndexerError::GenericError(err.to_string())); + return Err(IndexerError::Generic(err.to_string())); } for (chunk_num, chunk) in data.chunks(chunk_size).enumerate() { @@ -101,8 +101,7 @@ pub fn get_large_object_in_chunks( let mut data: Vec = vec![]; let mut chunk_num = 0; loop { - let length = - i32::try_from(chunk_size).map_err(|e| IndexerError::GenericError(e.to_string()))?; + let length = i32::try_from(chunk_size).map_err(|e| IndexerError::Generic(e.to_string()))?; let offset = (chunk_num * chunk_size) as i64; tracing::trace!("Fetching large-object chunk at offset {}", offset); diff --git a/crates/iota-indexer/src/models/objects.rs b/crates/iota-indexer/src/models/objects.rs index 76ba1c21f5c..4a165e6fc76 100644 --- a/crates/iota-indexer/src/models/objects.rs +++ b/crates/iota-indexer/src/models/objects.rs @@ -278,7 +278,7 @@ impl TryFrom for Object { fn try_from(o: StoredObject) -> Result { bcs::from_bytes(&o.serialized_object).map_err(|e| { - IndexerError::SerdeError(format!( + IndexerError::Serde(format!( "Failed to deserialize object: {:?}, error: {}", o.object_id, e )) @@ -294,7 +294,7 @@ impl StoredObject { let oref = self.get_object_ref()?; let object: iota_types::object::Object = self.try_into()?; let Some(move_object) = object.data.try_as_move().cloned() else { - return Err(IndexerError::PostgresReadError(format!( + return Err(IndexerError::PostgresRead(format!( "Object {:?} is not a Move object", oref, ))); @@ -304,7 +304,7 @@ impl StoredObject { .type_layout(move_object.type_().clone().into()) .await .map_err(|e| { - IndexerError::ResolveMoveStructError(format!( + IndexerError::ResolveMoveStruct(format!( "Failed to convert into object read for obj {}:{}, type: {}. Error: {e}", object.id(), object.version(), @@ -313,7 +313,7 @@ impl StoredObject { })?; 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(), )), }?; @@ -332,7 +332,7 @@ impl StoredObject { { Some(Ok(info)) => Ok(info), Some(Err(e)) => Err(e), - None => Err(IndexerError::PersistentStorageDataCorruptionError( + None => Err(IndexerError::PersistentStorageDataCorruption( "Dynamic field object has incompatible dynamic field type: empty df_kind".into(), )), } @@ -349,26 +349,26 @@ impl StoredObject { // Past this point, if there is any unexpected field, it's a data corruption // error let object_id = ObjectID::from_bytes(&self.object_id).map_err(|_| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Can't convert {:?} to object_id", self.object_id )) })?; let object_digest = ObjectDigest::try_from(self.object_digest.as_slice()).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "object {} has incompatible object digest. Error: {e}", object_id )) })?; let df_object_id = if let Some(df_object_id) = self.df_object_id.clone() { ObjectID::from_bytes(df_object_id).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "object {} has incompatible dynamic field type: df_object_id. Error: {e}", object_id )) }) } else { - return Err(IndexerError::PersistentStorageDataCorruptionError(format!( + return Err(IndexerError::PersistentStorageDataCorruption(format!( "object {} has incompatible dynamic field type: empty df_object_id", object_id ))); @@ -377,7 +377,7 @@ impl StoredObject { Some(0) => DynamicFieldType::DynamicField, Some(1) => DynamicFieldType::DynamicObject, _ => { - return Err(IndexerError::PersistentStorageDataCorruptionError(format!( + return Err(IndexerError::PersistentStorageDataCorruption(format!( "object {} has incompatible dynamic field type: empty df_kind", object_id ))); @@ -385,14 +385,14 @@ impl StoredObject { }; let name = if let Some(field_name) = self.df_name.clone() { let name: DynamicFieldName = bcs::from_bytes(&field_name).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "object {} has incompatible dynamic field type: df_name. Error: {e}", object_id )) })?; name } else { - return Err(IndexerError::PersistentStorageDataCorruptionError(format!( + return Err(IndexerError::PersistentStorageDataCorruption(format!( "object {} has incompatible dynamic field type: empty df_name", object_id ))); @@ -401,13 +401,13 @@ impl StoredObject { let oref = self.get_object_ref()?; let object: iota_types::object::Object = self.clone().try_into()?; let Some(move_object) = object.data.try_as_move().cloned() else { - return Err(IndexerError::PostgresReadError(format!( + return Err(IndexerError::PostgresRead(format!( "Object {:?} is not a Move object", oref, ))); }; if !move_object.type_().is_dynamic_field() { - return Err(IndexerError::PostgresReadError(format!( + return Err(IndexerError::PostgresRead(format!( "Object {:?} is not a dynamic field", oref, ))); @@ -417,7 +417,7 @@ impl StoredObject { .type_layout(name.type_.clone()) .await .map_err(|e| { - IndexerError::ResolveMoveStructError(format!( + IndexerError::ResolveMoveStruct(format!( "Failed to create dynamic field info for obj {}:{}, type: {}. Error: {e}", object.id(), object.version(), @@ -426,12 +426,13 @@ impl StoredObject { })?; let iota_json_value = iota_json::IotaJsonValue::new(name.value.clone())?; let bcs_name = iota_json_value.to_bcs_bytes(&layout)?; - let object_type = self.df_object_type.clone().ok_or( - IndexerError::PersistentStorageDataCorruptionError(format!( - "object {} has incompatible dynamic field type: empty df_object_type", - object_id - )), - )?; + let object_type = + self.df_object_type + .clone() + .ok_or(IndexerError::PersistentStorageDataCorruption(format!( + "object {} has incompatible dynamic field type: empty df_object_type", + object_id + )))?; Ok(Some(DynamicFieldInfo { version: oref.1, digest: object_digest, @@ -445,11 +446,11 @@ impl StoredObject { pub fn get_object_ref(&self) -> Result { let object_id = ObjectID::from_bytes(self.object_id.clone()).map_err(|_| { - IndexerError::SerdeError(format!("Can't convert {:?} to object_id", self.object_id)) + IndexerError::Serde(format!("Can't convert {:?} to object_id", self.object_id)) })?; let object_digest = ObjectDigest::try_from(self.object_digest.as_slice()).map_err(|_| { - IndexerError::SerdeError(format!( + IndexerError::Serde(format!( "Can't convert {:?} to object_digest", self.object_digest )) @@ -487,13 +488,13 @@ impl TryFrom for IotaCoin { let (coin_object_id, version, digest) = o.get_object_ref()?; let coin_type_canonical = o.coin_type - .ok_or(IndexerError::PersistentStorageDataCorruptionError(format!( + .ok_or(IndexerError::PersistentStorageDataCorruption(format!( "Object {} is supposed to be a coin but has an empty coin_type column", coin_object_id, )))?; let coin_type = parse_to_struct_tag(coin_type_canonical.as_str()) .map_err(|_| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "The type of object {} cannot be parsed as a struct tag", coin_object_id, )) @@ -501,7 +502,7 @@ impl TryFrom for IotaCoin { .to_string(); let balance = o .coin_balance - .ok_or(IndexerError::PersistentStorageDataCorruptionError(format!( + .ok_or(IndexerError::PersistentStorageDataCorruption(format!( "Object {} is supposed to be a coin but has an empty coin_balance column", coin_object_id, )))?; @@ -532,7 +533,7 @@ impl TryFrom for Balance { fn try_from(c: CoinBalance) -> Result { let coin_type = parse_to_struct_tag(c.coin_type.as_str()) .map_err(|_| { - IndexerError::PersistentStorageDataCorruptionError( + IndexerError::PersistentStorageDataCorruption( "The type of coin balance cannot be parsed as a struct tag".to_string(), ) })? diff --git a/crates/iota-indexer/src/models/transactions.rs b/crates/iota-indexer/src/models/transactions.rs index 2a56c1c54c9..16fe366bd58 100644 --- a/crates/iota-indexer/src/models/transactions.rs +++ b/crates/iota-indexer/src/models/transactions.rs @@ -249,7 +249,7 @@ impl StoredTransaction { let options = options.clone(); let tx_digest = TransactionDigest::try_from(self.transaction_digest.as_slice()).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Can't convert {:?} as tx_digest. Error: {e}", self.transaction_digest )) @@ -291,14 +291,14 @@ impl StoredTransaction { .map(|event| match event { Some(event) => { let event: Event = bcs::from_bytes(&event).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Can't convert event bytes into Event. tx_digest={:?} Error: {e}", tx_digest )) })?; Ok(event) } - None => Err(IndexerError::PersistentStorageDataCorruptionError(format!( + None => Err(IndexerError::PersistentStorageDataCorruption(format!( "Event should not be null, tx_digest={:?}", tx_digest ))), @@ -311,25 +311,25 @@ impl StoredTransaction { self.events .as_array() .ok_or_else(|| { - IndexerError::PersistentStorageDataCorruptionError( + IndexerError::PersistentStorageDataCorruption( "Failed to parse events as array".to_string(), ) })? .iter() .map(|event| match event { - serde_json::Value::Null => Err(IndexerError::PersistentStorageDataCorruptionError( + serde_json::Value::Null => Err(IndexerError::PersistentStorageDataCorruption( "events should not contain null elements".to_string(), )), serde_json::Value::String(event) => { let event: Event = bcs::from_bytes(event.as_bytes()).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Can't convert event bytes into Event. tx_digest={:?} Error: {e}", tx_digest )) })?; Ok(event) } - _ => Err(IndexerError::PersistentStorageDataCorruptionError( + _ => Err(IndexerError::PersistentStorageDataCorruption( "events should contain only string elements".to_string(), )), }) @@ -352,12 +352,12 @@ impl StoredTransaction { match object_change { Some(object_change) => { let object_change: IndexedObjectChange = bcs::from_bytes(&object_change) - .map_err(|e| IndexerError::PersistentStorageDataCorruptionError( + .map_err(|e| IndexerError::PersistentStorageDataCorruption( format!("Can't convert object_change bytes into IndexedObjectChange. tx_digest={:?} Error: {e}", tx_digest) ))?; Ok(ObjectChange::from(object_change)) } - None => Err(IndexerError::PersistentStorageDataCorruptionError(format!("object_change should not be null, tx_digest={:?}", tx_digest))), + None => Err(IndexerError::PersistentStorageDataCorruption(format!("object_change should not be null, tx_digest={:?}", tx_digest))), } }).collect::, IndexerError>>()? } @@ -367,23 +367,23 @@ impl StoredTransaction { self.object_changes .as_array() .ok_or_else(|| { - IndexerError::PersistentStorageDataCorruptionError( + IndexerError::PersistentStorageDataCorruption( "Failed to parse object_changes as array".to_string(), ) })? .iter() .map(|object_change| match object_change { - serde_json::Value::Null => Err(IndexerError::PersistentStorageDataCorruptionError( + serde_json::Value::Null => Err(IndexerError::PersistentStorageDataCorruption( "object_changes should not contain null elements".to_string(), )), serde_json::Value::String(object_change) => { let object_change: IndexedObjectChange = bcs::from_bytes(object_change.as_bytes()) - .map_err(|e| IndexerError::PersistentStorageDataCorruptionError( + .map_err(|e| IndexerError::PersistentStorageDataCorruption( format!("Can't convert object_change bytes into IndexedObjectChange. tx_digest={:?} Error: {e}", tx_digest) ))?; Ok(ObjectChange::from(object_change)) } - _ => Err(IndexerError::PersistentStorageDataCorruptionError( + _ => Err(IndexerError::PersistentStorageDataCorruption( "object_changes should contain only string elements".to_string(), )), }) @@ -403,12 +403,12 @@ impl StoredTransaction { match balance_change { Some(balance_change) => { let balance_change: BalanceChange = bcs::from_bytes(&balance_change) - .map_err(|e| IndexerError::PersistentStorageDataCorruptionError( + .map_err(|e| IndexerError::PersistentStorageDataCorruption( format!("Can't convert balance_change bytes into BalanceChange. tx_digest={:?} Error: {e}", tx_digest) ))?; Ok(balance_change) } - None => Err(IndexerError::PersistentStorageDataCorruptionError(format!("object_change should not be null, tx_digest={:?}", tx_digest))), + None => Err(IndexerError::PersistentStorageDataCorruption(format!("object_change should not be null, tx_digest={:?}", tx_digest))), } }).collect::, IndexerError>>()? } @@ -418,23 +418,23 @@ impl StoredTransaction { self.balance_changes .as_array() .ok_or_else(|| { - IndexerError::PersistentStorageDataCorruptionError( + IndexerError::PersistentStorageDataCorruption( "Failed to parse balance_changes as array".to_string(), ) })? .iter() .map(|balance_change| match balance_change { - serde_json::Value::Null => Err(IndexerError::PersistentStorageDataCorruptionError( + serde_json::Value::Null => Err(IndexerError::PersistentStorageDataCorruption( "balance_changes should not contain null elements".to_string(), )), serde_json::Value::String(balance_change) => { let balance_change: BalanceChange = bcs::from_bytes(balance_change.as_bytes()) - .map_err(|e| IndexerError::PersistentStorageDataCorruptionError( + .map_err(|e| IndexerError::PersistentStorageDataCorruption( format!("Can't convert balance_change bytes into BalanceChange. tx_digest={:?} Error: {e}", tx_digest) ))?; Ok(balance_change) } - _ => Err(IndexerError::PersistentStorageDataCorruptionError( + _ => Err(IndexerError::PersistentStorageDataCorruption( "balance_changes should contain only string elements".to_string(), )), }) @@ -465,7 +465,7 @@ impl StoredTransaction { fn try_into_sender_signed_data(&self) -> IndexerResult { let sender_signed_data: SenderSignedData = bcs::from_bytes(&self.raw_transaction).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Can't convert raw_transaction of {} into SenderSignedData. Error: {e}", self.tx_sequence_number )) @@ -475,7 +475,7 @@ impl StoredTransaction { pub fn try_into_iota_transaction_effects(&self) -> IndexerResult { let effects: TransactionEffects = bcs::from_bytes(&self.raw_effects).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Can't convert raw_effects of {} into TransactionEffects. Error: {e}", self.tx_sequence_number )) @@ -559,9 +559,9 @@ impl StoredTransaction { ) -> Result { tracing::debug!("Setting large object data as raw transaction"); let raw_oid = std::mem::take(&mut self.raw_transaction); - let raw_oid: [u8; 4] = raw_oid.try_into().map_err(|_| { - IndexerError::GenericError("invalid large object identifier".to_owned()) - })?; + let raw_oid: [u8; 4] = raw_oid + .try_into() + .map_err(|_| IndexerError::Generic("invalid large object identifier".to_owned()))?; let oid = u32::from_le_bytes(raw_oid); self.raw_transaction = @@ -578,9 +578,9 @@ impl StoredTransaction { ) -> Result { tracing::debug!("Setting large object data as raw effects"); let raw_oid = std::mem::take(&mut self.raw_effects); - let raw_oid: [u8; 4] = raw_oid.try_into().map_err(|_| { - IndexerError::GenericError("invalid large object identifier".to_owned()) - })?; + let raw_oid: [u8; 4] = raw_oid + .try_into() + .map_err(|_| IndexerError::Generic("invalid large object identifier".to_owned()))?; let oid = u32::from_le_bytes(raw_oid); self.raw_effects = get_large_object_in_chunks(oid, Self::LARGE_OBJECT_CHUNK_SIZE, pool)?; @@ -598,14 +598,13 @@ impl StoredTransaction { let raw_oid = std::mem::take(&mut self.object_changes) .pop() .flatten() - .ok_or_else(|| { - IndexerError::GenericError("invalid large object identifier".to_owned()) - })?; + .ok_or_else(|| IndexerError::Generic("invalid large object identifier".to_owned()))?; // The first values is the raw oid - let oid = u32::from_le_bytes(raw_oid.try_into().map_err(|_| { - IndexerError::GenericError("invalid large object identifier".to_owned()) - })?); + let oid = + u32::from_le_bytes(raw_oid.try_into().map_err(|_| { + IndexerError::Generic("invalid large object identifier".to_owned()) + })?); let stored_data = get_large_object_in_chunks(oid, Self::LARGE_OBJECT_CHUNK_SIZE, pool)?; self.object_changes = bcs::from_bytes(&stored_data) .map_err(IndexerError::from) @@ -641,13 +640,13 @@ pub fn stored_events_to_events( .map(|event| match event { Some(event) => { let event: Event = bcs::from_bytes(&event).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Can't convert event bytes into Event. Error: {e}", )) })?; Ok(event) } - None => Err(IndexerError::PersistentStorageDataCorruptionError( + None => Err(IndexerError::PersistentStorageDataCorruption( "Event should not be null".to_string(), )), }) @@ -659,24 +658,24 @@ pub fn stored_events_to_events( stored_events .as_array() .ok_or_else(|| { - IndexerError::PersistentStorageDataCorruptionError( + IndexerError::PersistentStorageDataCorruption( "Failed to parse events as array".to_string(), ) })? .iter() .map(|event| match event { - serde_json::Value::Null => Err(IndexerError::PersistentStorageDataCorruptionError( + serde_json::Value::Null => Err(IndexerError::PersistentStorageDataCorruption( "events should not contain null elements".to_string(), )), serde_json::Value::String(event) => { let event: Event = bcs::from_bytes(event.as_bytes()).map_err(|e| { - IndexerError::PersistentStorageDataCorruptionError(format!( + IndexerError::PersistentStorageDataCorruption(format!( "Can't convert event bytes into Event. Error: {e}", )) })?; Ok(event) } - _ => Err(IndexerError::PersistentStorageDataCorruptionError( + _ => Err(IndexerError::PersistentStorageDataCorruption( "events should contain only string elements".to_string(), )), }) @@ -708,7 +707,7 @@ pub async fn tx_events_to_iota_tx_events( .into_iter() .collect::, _>>() .map_err(|e| { - IndexerError::ResolveMoveStructError(format!( + IndexerError::ResolveMoveStruct(format!( "Failed to convert to iota event with Error: {e}", )) })?; diff --git a/crates/iota-indexer/src/processors/network_metrics_processor.rs b/crates/iota-indexer/src/processors/network_metrics_processor.rs index bee9937d8cf..5df244a0c91 100644 --- a/crates/iota-indexer/src/processors/network_metrics_processor.rs +++ b/crates/iota-indexer/src/processors/network_metrics_processor.rs @@ -115,7 +115,7 @@ where .get_checkpoints_in_range(last_processed_cp_seq, last_processed_cp_seq + 1) .await? .first() - .ok_or(IndexerError::PostgresReadError( + .ok_or(IndexerError::PostgresRead( "Cannot read checkpoint from PG for epoch peak TPS".to_string(), ))? .clone(); diff --git a/crates/iota-indexer/src/store/mod.rs b/crates/iota-indexer/src/store/mod.rs index 39cb3bacf53..3faab3daf58 100644 --- a/crates/iota-indexer/src/store/mod.rs +++ b/crates/iota-indexer/src/store/mod.rs @@ -35,7 +35,7 @@ pub mod diesel_macro { .read_only() .repeatable_read() .run($query) - .map_err(|e| IndexerError::PostgresReadError(e.to_string())) + .map_err(|e| IndexerError::PostgresRead(e.to_string())) } #[cfg(feature = "mysql-feature")] #[cfg(not(feature = "postgres-feature"))] @@ -46,7 +46,7 @@ pub mod diesel_macro { .downcast_mut::>() .unwrap() .transaction($query) - .map_err(|e| IndexerError::PostgresReadError(e.to_string())) + .map_err(|e| IndexerError::PostgresRead(e.to_string())) } }}; } @@ -66,7 +66,7 @@ pub mod diesel_macro { .build_transaction() .read_only() .run($query) - .map_err(|e| IndexerError::PostgresReadError(e.to_string())) + .map_err(|e| IndexerError::PostgresRead(e.to_string())) } #[cfg(feature = "mysql-feature")] #[cfg(not(feature = "postgres-feature"))] @@ -78,7 +78,7 @@ pub mod diesel_macro { .downcast_mut::>() .unwrap() .transaction($query) - .map_err(|e| IndexerError::PostgresReadError(e.to_string())) + .map_err(|e| IndexerError::PostgresRead(e.to_string())) } }}; } @@ -97,7 +97,7 @@ pub mod diesel_macro { { let mut pool_conn = get_pool_connection($pool).map_err(|e| backoff::Error::Transient { - err: IndexerError::PostgresWriteError(e.to_string()), + err: IndexerError::PostgresWrite(e.to_string()), retry_after: None, })?; pool_conn @@ -113,7 +113,7 @@ pub mod diesel_macro { e ); backoff::Error::Transient { - err: IndexerError::PostgresWriteError(e.to_string()), + err: IndexerError::PostgresWrite(e.to_string()), retry_after: None, } }) @@ -124,7 +124,7 @@ pub mod diesel_macro { use diesel::Connection; let mut pool_conn = get_pool_connection($pool).map_err(|e| backoff::Error::Transient { - err: IndexerError::PostgresWriteError(e.to_string()), + err: IndexerError::PostgresWrite(e.to_string()), retry_after: None, })?; pool_conn @@ -132,14 +132,14 @@ pub mod diesel_macro { .downcast_mut::>() .unwrap() .transaction($query) - .map_err(|e| IndexerError::PostgresReadError(e.to_string())) + .map_err(|e| IndexerError::PostgresRead(e.to_string())) .map_err(|e| { tracing::error!( "Error with persisting data into DB: {:?}, retrying...", e ); backoff::Error::Transient { - err: IndexerError::PostgresWriteError(e.to_string()), + err: IndexerError::PostgresWrite(e.to_string()), retry_after: None, } }) @@ -180,7 +180,7 @@ pub mod diesel_macro { .read_only() .repeatable_read() .run($query) - .map_err(|e| IndexerError::PostgresReadError(e.to_string())) + .map_err(|e| IndexerError::PostgresRead(e.to_string())) } else { pool_conn .as_any_mut() @@ -189,7 +189,7 @@ pub mod diesel_macro { .build_transaction() .read_only() .run($query) - .map_err(|e| IndexerError::PostgresReadError(e.to_string())) + .map_err(|e| IndexerError::PostgresRead(e.to_string())) } } #[cfg(feature = "mysql-feature")] @@ -201,7 +201,7 @@ pub mod diesel_macro { .downcast_mut::>() .unwrap() .transaction($query) - .map_err(|e| IndexerError::PostgresReadError(e.to_string())) + .map_err(|e| IndexerError::PostgresRead(e.to_string())) } }) .await diff --git a/crates/iota-indexer/src/store/package_resolver.rs b/crates/iota-indexer/src/store/package_resolver.rs index 04c99483799..7bca7a2612f 100644 --- a/crates/iota-indexer/src/store/package_resolver.rs +++ b/crates/iota-indexer/src/store/package_resolver.rs @@ -57,14 +57,14 @@ impl IndexerStorePackageResolver { query.get_result::>(conn).optional() })? else { - return Err(IndexerError::PostgresReadError(format!( + return Err(IndexerError::PostgresRead(format!( "Package not found in DB: {:?}", id ))); }; let object = bcs::from_bytes::(&bcs)?; Package::read_from_object(&object).map_err(|e| { - IndexerError::PostgresReadError(format!("Failed parsing object to package: {:?}", e)) + IndexerError::PostgresRead(format!("Failed parsing object to package: {:?}", e)) }) } diff --git a/crates/iota-indexer/src/store/pg_indexer_store.rs b/crates/iota-indexer/src/store/pg_indexer_store.rs index a43e6c5988e..d721a5e95e4 100644 --- a/crates/iota-indexer/src/store/pg_indexer_store.rs +++ b/crates/iota-indexer/src/store/pg_indexer_store.rs @@ -990,7 +990,7 @@ impl PgIndexerStore { .into_iter() .collect::, _>>() .map_err(|e| { - IndexerError::PostgresWriteError(format!( + IndexerError::PostgresWrite(format!( "Failed to persist all event indices in a chunk: {:?}", e )) @@ -1261,7 +1261,7 @@ impl PgIndexerStore { .into_iter() .collect::, _>>() .map_err(|e| { - IndexerError::PostgresWriteError(format!( + IndexerError::PostgresWrite(format!( "Failed to persist all tx indices in a chunk: {:?}", e )) @@ -1729,7 +1729,7 @@ impl IndexerStore for PgIndexerStore { .into_iter() .collect::, _>>() .map_err(|e| { - IndexerError::PostgresWriteError(format!( + IndexerError::PostgresWrite(format!( "Failed to persist all object mutation chunks: {:?}", e )) @@ -1749,7 +1749,7 @@ impl IndexerStore for PgIndexerStore { .into_iter() .collect::, _>>() .map_err(|e| { - IndexerError::PostgresWriteError(format!( + IndexerError::PostgresWrite(format!( "Failed to persist all object deletion chunks: {:?}", e )) @@ -1796,7 +1796,7 @@ impl IndexerStore for PgIndexerStore { .into_iter() .collect::, _>>() .map_err(|e| { - IndexerError::PostgresWriteError(format!( + IndexerError::PostgresWrite(format!( "Failed to persist all objects snapshot chunks: {:?}", e )) @@ -1845,7 +1845,7 @@ impl IndexerStore for PgIndexerStore { .into_iter() .collect::, _>>() .map_err(|e| { - IndexerError::PostgresWriteError(format!( + IndexerError::PostgresWrite(format!( "Failed to persist all objects history chunks: {:?}", e )) @@ -1873,10 +1873,7 @@ impl IndexerStore for PgIndexerStore { self.spawn_blocking_task(move |this| this.update_objects_snapshot(start_cp, end_cp)) .await .map_err(|e| { - IndexerError::PostgresWriteError(format!( - "Failed to update objects snapshot: {:?}", - e - )) + IndexerError::PostgresWrite(format!("Failed to update objects snapshot: {:?}", e)) })??; let elapsed = guard.stop_and_record(); info!( @@ -1918,7 +1915,7 @@ impl IndexerStore for PgIndexerStore { .into_iter() .collect::, _>>() .map_err(|e| { - IndexerError::PostgresWriteError(format!( + IndexerError::PostgresWrite(format!( "Failed to persist all transactions chunks: {:?}", e )) @@ -1951,10 +1948,7 @@ impl IndexerStore for PgIndexerStore { .into_iter() .collect::, _>>() .map_err(|e| { - IndexerError::PostgresWriteError(format!( - "Failed to persist all events chunks: {:?}", - e - )) + IndexerError::PostgresWrite(format!("Failed to persist all events chunks: {:?}", e)) })?; let elapsed = guard.stop_and_record(); info!(elapsed, "Persisted {} events", len); @@ -2007,7 +2001,7 @@ impl IndexerStore for PgIndexerStore { .into_iter() .collect::, _>>() .map_err(|e| { - IndexerError::PostgresWriteError(format!( + IndexerError::PostgresWrite(format!( "Failed to persist all event_indices chunks: {:?}", e )) @@ -2042,7 +2036,7 @@ impl IndexerStore for PgIndexerStore { .into_iter() .collect::, _>>() .map_err(|e| { - IndexerError::PostgresWriteError(format!( + IndexerError::PostgresWrite(format!( "Failed to persist all tx_indices chunks: {:?}", e )) @@ -2065,7 +2059,7 @@ impl IndexerStore for PgIndexerStore { async fn prune_epoch(&self, epoch: u64) -> Result<(), IndexerError> { let (mut min_cp, max_cp) = match self.get_checkpoint_range_for_epoch(epoch)? { (min_cp, Some(max_cp)) => Ok((min_cp, max_cp)), - _ => Err(IndexerError::PostgresReadError(format!( + _ => Err(IndexerError::PostgresRead(format!( "Failed to get checkpoint range for epoch {}", epoch ))), @@ -2191,7 +2185,7 @@ impl IndexerStore for PgIndexerStore { (version as u64).into(), chain_id.chain(), ) - .ok_or(IndexerError::GenericError(format!( + .ok_or(IndexerError::Generic(format!( "Unable to fetch protocol version {} and chain {:?}", version, chain_id.chain() diff --git a/crates/iota-indexer/src/types.rs b/crates/iota-indexer/src/types.rs index b4493b66ebb..d193e65da1e 100644 --- a/crates/iota-indexer/src/types.rs +++ b/crates/iota-indexer/src/types.rs @@ -288,7 +288,7 @@ impl TryFrom for ObjectStatus { 0 => ObjectStatus::Active, 1 => ObjectStatus::WrappedOrDeleted, value => { - return Err(IndexerError::PersistentStorageDataCorruptionError(format!( + return Err(IndexerError::PersistentStorageDataCorruption(format!( "{value} as ObjectStatus" ))); } @@ -306,7 +306,7 @@ impl TryFrom for OwnerType { 2 => OwnerType::Object, 3 => OwnerType::Shared, value => { - return Err(IndexerError::PersistentStorageDataCorruptionError(format!( + return Err(IndexerError::PersistentStorageDataCorruption(format!( "{value} as OwnerType" ))); } diff --git a/crates/iota-indexer/tests/ingestion_tests.rs b/crates/iota-indexer/tests/ingestion_tests.rs index 9c96926d164..cbc95d9b67d 100644 --- a/crates/iota-indexer/tests/ingestion_tests.rs +++ b/crates/iota-indexer/tests/ingestion_tests.rs @@ -30,7 +30,7 @@ mod ingestion_tests { .build_transaction() .read_only() .run($query) - .map_err(|e| IndexerError::PostgresReadError(e.to_string())) + .map_err(|e| IndexerError::PostgresRead(e.to_string())) }}; }