From 0de26e04e2bd1fb8f21d19efbc1781d207dc1ef4 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 23 Aug 2022 18:03:30 +0300 Subject: [PATCH] Specialize metadata errors Signed-off-by: Alexandru Vasile --- subxt/src/constants/constants_client.rs | 6 +++++- subxt/src/metadata/metadata_type.rs | 12 +++++++++--- subxt/src/storage/storage_client.rs | 8 +++++++- subxt/src/tx/tx_client.rs | 6 +++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/subxt/src/constants/constants_client.rs b/subxt/src/constants/constants_client.rs index 5a12889b2c..a779ab2de5 100644 --- a/subxt/src/constants/constants_client.rs +++ b/subxt/src/constants/constants_client.rs @@ -47,7 +47,11 @@ impl> ConstantsClient { .metadata() .constant_hash(address.pallet_name(), address.constant_name())?; if actual_hash != expected_hash { - return Err(MetadataError::IncompatibleMetadata.into()) + return Err(MetadataError::IncompatibleConstantMetadata( + address.pallet_name().into(), + address.constant_name().into(), + ) + .into()) } } Ok(()) diff --git a/subxt/src/metadata/metadata_type.rs b/subxt/src/metadata/metadata_type.rs index 9e19a4e6ec..e9be538b14 100644 --- a/subxt/src/metadata/metadata_type.rs +++ b/subxt/src/metadata/metadata_type.rs @@ -60,9 +60,15 @@ pub enum MetadataError { /// Type is not in metadata. #[error("Type {0} missing from type registry")] TypeNotFound(u32), - /// Runtime pallet metadata is incompatible with the static one. - #[error("Pallet {0} has incompatible metadata")] - IncompatiblePalletMetadata(&'static str), + /// Runtime constant metadata is incompatible with the static one. + #[error("Pallet {0} Constant {0} has incompatible metadata")] + IncompatibleConstantMetadata(String, String), + /// Runtime call metadata is incompatible with the static one. + #[error("Pallet {0} Call {0} has incompatible metadata")] + IncompatibleCallMetadata(String, String), + /// Runtime storage metadata is incompatible with the static one. + #[error("Pallet {0} Storage {0} has incompatible metadata")] + IncompatibleStorageMetadata(String, String), /// Runtime metadata is not fully compatible with the static one. #[error("Node metadata is not fully compatible")] IncompatibleMetadata, diff --git a/subxt/src/storage/storage_client.rs b/subxt/src/storage/storage_client.rs index 262ee6f78c..af3635f330 100644 --- a/subxt/src/storage/storage_client.rs +++ b/subxt/src/storage/storage_client.rs @@ -386,7 +386,13 @@ fn validate_storage( }; match expected_hash == hash { true => Ok(()), - false => Err(crate::error::MetadataError::IncompatibleMetadata.into()), + false => { + Err(crate::error::MetadataError::IncompatibleStorageMetadata( + pallet_name.into(), + storage_name.into(), + ) + .into()) + } } } diff --git a/subxt/src/tx/tx_client.rs b/subxt/src/tx/tx_client.rs index b35e0586b3..36d250fdbb 100644 --- a/subxt/src/tx/tx_client.rs +++ b/subxt/src/tx/tx_client.rs @@ -62,7 +62,11 @@ impl> TxClient { let expected_hash = metadata.call_hash(call.pallet_name(), call.call_name())?; if actual_hash != expected_hash { - return Err(crate::metadata::MetadataError::IncompatibleMetadata.into()) + return Err(crate::metadata::MetadataError::IncompatibleCallMetadata( + call.pallet_name().into(), + call.call_name().into(), + ) + .into()) } } Ok(())