From 59ba52a27de449ccf9c67ec01b32bce17f10c183 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 21 Aug 2024 08:29:22 -0500 Subject: [PATCH] type_tag: include source string in parse error --- crates/sui-sdk/src/types/type_tag/mod.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/sui-sdk/src/types/type_tag/mod.rs b/crates/sui-sdk/src/types/type_tag/mod.rs index 6b7f18f6b..d0a04e69c 100644 --- a/crates/sui-sdk/src/types/type_tag/mod.rs +++ b/crates/sui-sdk/src/types/type_tag/mod.rs @@ -47,13 +47,14 @@ impl std::str::FromStr for TypeTag { type Err = TypeParseError; fn from_str(s: &str) -> Result { - parse::parse_type_tag(s).map_err(|_| TypeParseError) + parse::parse_type_tag(s).map_err(|_| TypeParseError { source: s.into() }) } } -//TODO flesh out this error type #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] -pub struct TypeParseError; +pub struct TypeParseError { + source: String, +} impl std::fmt::Display for TypeParseError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -80,7 +81,9 @@ impl Identifier { pub fn new>(identifier: T) -> Result { parse::parse_identifier(identifier.as_ref()) .map(|ident| Self(ident.into())) - .map_err(|_| TypeParseError) + .map_err(|_| TypeParseError { + source: identifier.as_ref().into(), + }) } pub fn into_inner(self) -> Box { @@ -104,7 +107,7 @@ impl std::str::FromStr for Identifier { fn from_str(s: &str) -> Result { parse::parse_identifier(s) .map(|ident| Self(ident.into())) - .map_err(|_| TypeParseError) + .map_err(|_| TypeParseError { source: s.into() }) } } @@ -192,6 +195,6 @@ impl std::str::FromStr for StructTag { type Err = TypeParseError; fn from_str(s: &str) -> Result { - parse::parse_struct_tag(s).map_err(|_| TypeParseError) + parse::parse_struct_tag(s).map_err(|_| TypeParseError { source: s.into() }) } }