Skip to content

Commit

Permalink
chore(iota-sdk): Error cleanup (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Jul 25, 2024
1 parent 7af45da commit e1e307c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/iota-replay/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl From<IotaError> for ReplayEngineError {
impl From<IotaRpcError> for ReplayEngineError {
fn from(err: IotaRpcError) -> Self {
match err {
IotaRpcError::RpcError(JsonRpseeError::RequestTimeout) => {
IotaRpcError::Rpc(JsonRpseeError::RequestTimeout) => {
ReplayEngineError::IotaRpcRequestTimeout
}
_ => ReplayEngineError::IotaRpcError {
Expand Down
4 changes: 2 additions & 2 deletions crates/iota-sdk/examples/json_rpc_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ async fn main() -> Result<(), anyhow::Error> {
.get_coins(active_address, coin_type.clone(), None, Some(5))
.await;
let error = coins.unwrap_err();
if let Error::RpcError(rpc_error) = error {
if let Error::Rpc(rpc_error) = error {
let converted: JsonRpcError = rpc_error.into();
println!(" *** RpcError ***");
println!("{converted}");
println!("{}", converted.is_client_error());
} else {
bail!("Expected Error::RpcError, got {:?}", error);
bail!("Expected Error::Rpc, got {:?}", error);
}
Ok(())
}
4 changes: 2 additions & 2 deletions crates/iota-sdk/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,11 @@ impl ReadApi {
.await?
.into_object()
.map_err(|e| {
Error::DataError(format!("Can't get bcs of object {:?}: {:?}", object_id, e))
Error::Data(format!("Can't get bcs of object {:?}: {:?}", object_id, e))
})?;
// unwrap: requested bcs data
let move_object = resp.bcs.unwrap();
let raw_move_obj = move_object.try_into_move().ok_or(Error::DataError(format!(
let raw_move_obj = move_object.try_into_move().ok_or(Error::Data(format!(
"Object {:?} is not a MoveObject",
object_id
)))?;
Expand Down
15 changes: 4 additions & 11 deletions crates/iota-sdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use iota_types::{
base_types::{IotaAddress, TransactionDigest},
error::UserInputError,
};
use iota_types::base_types::{IotaAddress, TransactionDigest};
use thiserror::Error;

pub use crate::json_rpc_error::Error as JsonRpcError;
Expand All @@ -15,19 +12,15 @@ pub type IotaRpcResult<T = ()> = Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
RpcError(#[from] jsonrpsee::core::Error),
Rpc(#[from] jsonrpsee::core::Error),
#[error(transparent)]
JsonRpcError(JsonRpcError),
#[error(transparent)]
BcsSerialisationError(#[from] bcs::Error),
#[error(transparent)]
UserInputError(#[from] UserInputError),
BcsSerialization(#[from] bcs::Error),
#[error("Subscription error : {0}")]
Subscription(String),
#[error("Failed to confirm tx status for {0:?} within {1} seconds.")]
FailToConfirmTransactionStatus(TransactionDigest, u64),
#[error("Data error: {0}")]
DataError(String),
Data(String),
#[error(
"Client/Server api version mismatch, client api version : {client_version}, server api version : {server_version}"
)]
Expand Down
6 changes: 2 additions & 4 deletions crates/iota-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl IotaClientBuilder {
.pointer("/info/version")
.and_then(|v| v.as_str())
.ok_or_else(|| {
Error::DataError("Fail parsing server version from rpc.discover endpoint.".into())
Error::Data("Fail parsing server version from rpc.discover endpoint.".into())
})?;
let rpc_methods = Self::parse_methods(&rpc_spec)?;

Expand All @@ -362,9 +362,7 @@ impl IotaClientBuilder {
.pointer("/methods")
.and_then(|methods| methods.as_array())
.ok_or_else(|| {
Error::DataError(
"Fail parsing server information from rpc.discover endpoint.".into(),
)
Error::Data("Fail parsing server information from rpc.discover endpoint.".into())
})?;

Ok(methods
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-source-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl<'a> BytecodeSourceVerifier<'a> {
.map_err(SourceVerificationError::IotaObjectRefFailure)?
.bcs
.ok_or_else(|| {
SourceVerificationError::DependencyObjectReadFailure(Error::DataError(
SourceVerificationError::DependencyObjectReadFailure(Error::Data(
"Bcs field is not found".to_string(),
))
})?;
Expand Down

0 comments on commit e1e307c

Please sign in to comment.