Skip to content

Commit 52e6386

Browse files
feat: improve error handling
This removes a seemingly redundant and not very illuminating error variant. It also ensures that the error message from the `Url` crate is displayed when displaying `UrlParseError`.
1 parent 070dc55 commit 52e6386

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,7 @@ impl GitUrl {
156156
/// Returns a `Result<GitUrl>` after normalizing and parsing `url` for metadata
157157
pub fn parse(url: &str) -> Result<GitUrl, GitUrlParseError> {
158158
// Normalize the url so we can use Url crate to process ssh urls
159-
let normalized = if let Ok(url) = normalize_url(url) {
160-
url
161-
} else {
162-
return Err(GitUrlParseError::UrlNormalizeFailed);
163-
};
159+
let normalized = normalize_url(url)?;
164160

165161
// Some pre-processing for paths
166162
let scheme = if let Ok(scheme) = Scheme::from_str(normalized.scheme()) {
@@ -485,12 +481,9 @@ fn is_ssh_url(url: &str) -> bool {
485481

486482
#[derive(Error, Debug, PartialEq, Eq)]
487483
pub enum GitUrlParseError {
488-
#[error("Error from Url crate")]
484+
#[error("Error from Url crate: {0}")]
489485
UrlParseError(#[from] url::ParseError),
490486

491-
#[error("Url normalization into url::Url failed")]
492-
UrlNormalizeFailed,
493-
494487
#[error("No url scheme was found, then failed to normalize as ssh url.")]
495488
SshUrlNormalizeFailedNoScheme,
496489

tests/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ fn bad_port_number() {
383383
assert!(e.is_err());
384384
assert_eq!(
385385
format!("{}", e.err().unwrap()),
386-
"Url normalization into url::Url failed"
386+
"Error from Url crate: invalid port number"
387387
);
388388
}
389389

0 commit comments

Comments
 (0)