Skip to content

Commit

Permalink
chore(wasix): Minor QueryError code cleanup
Browse files Browse the repository at this point in the history
Use Self:: instead of QueryError::
  • Loading branch information
theduke committed Dec 21, 2023
1 parent a41d95f commit e6622f1
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lib/wasix/src/runtime/resolver/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,17 @@ pub enum QueryError {

impl From<anyhow::Error> for QueryError {
fn from(value: anyhow::Error) -> Self {
QueryError::Other(value)
Self::Other(value)
}
}

impl Display for QueryError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
QueryError::Unsupported => {
f.write_str("This type of package specifier isn't supported")
}
QueryError::NotFound => f.write_str("Not found"),
QueryError::Timeout => f.write_str("Timed out"),
QueryError::NoMatches { archived_versions } => match archived_versions.as_slice() {
Self::Unsupported => f.write_str("This type of package specifier isn't supported"),
Self::NotFound => f.write_str("Not found"),
Self::Timeout => f.write_str("Timed out"),
Self::NoMatches { archived_versions } => match archived_versions.as_slice() {
[] => f.write_str(
"The package was found, but no published versions matched the constraint",
),
Expand All @@ -82,19 +80,16 @@ impl Display for QueryError {
)
}
},
QueryError::Other(e) => Display::fmt(e, f),
Self::Other(e) => Display::fmt(e, f),
}
}
}

impl std::error::Error for QueryError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
QueryError::Other(e) => Some(&**e),
QueryError::Unsupported
| QueryError::NotFound
| QueryError::NoMatches
| QueryError::Timeout { .. } => None,
Self::Other(e) => Some(&**e),
Self::Unsupported | Self::NotFound | Self::NoMatches { .. } | Self::Timeout => None,
}
}
}

0 comments on commit e6622f1

Please sign in to comment.