From 5e593e375a578f8442a86f77e2be899e66ce96b2 Mon Sep 17 00:00:00 2001 From: Thomas Niederberger Date: Mon, 28 Oct 2024 09:11:13 +0100 Subject: [PATCH] Expand Error type for event related problems --- src/api/error.rs | 4 ++++ src/api/mod.rs | 2 +- src/api/rpc_api/author.rs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/api/error.rs b/src/api/error.rs index b738d3bc1..ea4f92397 100644 --- a/src/api/error.rs +++ b/src/api/error.rs @@ -56,6 +56,10 @@ pub enum Error { BlockHashNotFound, /// Could not find the expected block. BlockNotFound, + /// Operation needs events but events are missing. + EventsMissing, + /// Operation wants to add events but they are already present. + EventsAlreadyPresent, /// Any custom Error. Other(Box), } diff --git a/src/api/mod.rs b/src/api/mod.rs index 279c1f8a1..4a35f5abd 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -70,7 +70,7 @@ impl ExtrinsicReport { /// Returns an error if the events are missing or if one of the events indicates a problem. pub fn check_events_for_dispatch_error(&self, metadata: &Metadata) -> Result<()> { if self.events.is_none() { - return Err(Error::Other("Report does not contain any events".into())) + return Err(Error::EventsMissing) } // Check if the extrinsic was successful or not. let events = self.events.as_ref().unwrap(); diff --git a/src/api/rpc_api/author.rs b/src/api/rpc_api/author.rs index 599e3a70e..21eeadaa1 100644 --- a/src/api/rpc_api/author.rs +++ b/src/api/rpc_api/author.rs @@ -288,7 +288,7 @@ where async fn populate_events(&self, report: &mut ExtrinsicReport) -> Result<()> { if report.events.is_some() { - return Err(Error::Other("Report already contains events".into())) + return Err(Error::EventsAlreadyPresent) } let block_hash = report.block_hash.ok_or(Error::BlockHashNotFound)?; let extrinsic_events =