Skip to content

Commit

Permalink
uri: Fix URI error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Sep 9, 2024
1 parent bcff619 commit 6a598b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,9 @@ impl FromStr for Password {
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Copy, derive_more::Display, Error)]
#[non_exhaustive]
pub enum ParseCodeError {
/// The code is empty
#[display("The code is empty")]
Empty,
/// A code must contain at least one '-' to separate nameplate from password
#[display("A code must contain at least one '-' to separate nameplate from password")]
SeparatorMissing,
Expand Down Expand Up @@ -1153,6 +1156,7 @@ impl FromStr for Code {

Ok(Self(format!("{}-{}", nameplate, password)))
},
None if s.is_empty() => Err(ParseCodeError::Empty),
None => Err(ParseCodeError::SeparatorMissing),
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ impl TryFrom<&url::Url> for WormholeTransferUri {
};
let code: Code = percent_encoding::percent_decode_str(url.path())
.decode_utf8()?
.parse()?;
.parse()
.map_err(|e| {
// TODO: Remove for 0.8
if matches!(e, ParseCodeError::Empty) {
ParseError::MissingCode
} else {
e.into()
}
})?;

Ok(WormholeTransferUri {
code,
Expand Down

0 comments on commit 6a598b7

Please sign in to comment.