-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: error/help messages #95
Conversation
src/main.rs
Outdated
@@ -96,7 +96,7 @@ enum Commands { | |||
/// Create a basin. | |||
CreateBasin { | |||
/// Name of the basin to create. | |||
basin: BasinNameOnlyUri, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not work apparently :o
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Work in what way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesnt render out the miette diagnostic! not sure why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because it's a clap parse error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup I assumed clap won't show that after trying a few hacks, feel free to push here in case you find a better way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's a better way, but, we can assume in this case, it isn't a valid basin name. None
scheme basically means that the input is at-max a valid file path which doesn't strongly imply that the user tried to input a URI. We can just return the parse basin error in this case?
diff --git a/src/types.rs b/src/types.rs
index 14d931a..cc249d4 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -33,7 +33,7 @@ fn parse_maybe_basin_or_uri(
}
Err(parse_basin_err) => {
// Should definitely be a URI else error.
- let uri = http::Uri::from_str(s).map_err(|_| parse_basin_err)?;
+ let uri = http::Uri::from_str(s).map_err(|_| parse_basin_err.clone())?;
match uri.scheme_str() {
Some("s2") => (),
@@ -45,10 +45,9 @@ fn parse_maybe_basin_or_uri(
)));
}
None => {
- return Err(BasinNameOrUriParseError::InvalidUri(miette::miette!(
- help = "Make sure the URI starts with 's2://'",
- "Missing URI scheme"
- )))
+ // It's probably not an attempt to enter a URI. Safe to
+ // assume this is simply an invalid basin.
+ return Err(parse_basin_err.into());
}
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as trying to return error with help message goes, we'll just have to format the error ourselves or do what you did.
What you did in this PR isn't the worst option. I would, though, prefer we do it consistently for all the commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just need to undo some changes :)
src/error.rs
Outdated
|
||
#[error(transparent)] | ||
#[diagnostic(transparent)] | ||
BasinUriParse(#[from] BasinNameOrUriParseError), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove this.
src/main.rs
Outdated
@@ -96,7 +96,7 @@ enum Commands { | |||
/// Create a basin. | |||
CreateBasin { | |||
/// Name of the basin to create. | |||
basin: BasinNameOnlyUri, | |||
basin: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can undo this.
No description provided.