Skip to content

Commit

Permalink
type_tag: include source string in parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Aug 21, 2024
1 parent bd233b6 commit 59ba52a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions crates/sui-sdk/src/types/type_tag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ impl std::str::FromStr for TypeTag {
type Err = TypeParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
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 {
Expand All @@ -80,7 +81,9 @@ impl Identifier {
pub fn new<T: AsRef<str>>(identifier: T) -> Result<Self, TypeParseError> {
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<str> {
Expand All @@ -104,7 +107,7 @@ impl std::str::FromStr for Identifier {
fn from_str(s: &str) -> Result<Self, Self::Err> {
parse::parse_identifier(s)
.map(|ident| Self(ident.into()))
.map_err(|_| TypeParseError)
.map_err(|_| TypeParseError { source: s.into() })
}
}

Expand Down Expand Up @@ -192,6 +195,6 @@ impl std::str::FromStr for StructTag {
type Err = TypeParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
parse::parse_struct_tag(s).map_err(|_| TypeParseError)
parse::parse_struct_tag(s).map_err(|_| TypeParseError { source: s.into() })
}
}

0 comments on commit 59ba52a

Please sign in to comment.