Skip to content
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

Merged
merged 5 commits into from
Dec 23, 2024
Merged

fix: error/help messages #95

merged 5 commits into from
Dec 23, 2024

Conversation

infiniteregrets
Copy link
Member

No description provided.

@infiniteregrets infiniteregrets requested a review from a team as a code owner December 23, 2024 00:50
src/main.rs Outdated
@@ -96,7 +96,7 @@ enum Commands {
/// Create a basin.
CreateBasin {
/// Name of the basin to create.
basin: BasinNameOnlyUri,
Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Work in what way?

Copy link
Member Author

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

Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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());
                 }
             };

Copy link
Member

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.

Copy link
Member

@vrongmeal vrongmeal left a 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
Comment on lines 55 to 58

#[error(transparent)]
#[diagnostic(transparent)]
BasinUriParse(#[from] BasinNameOrUriParseError),
Copy link
Member

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can undo this.

@infiniteregrets infiniteregrets merged commit af18134 into main Dec 23, 2024
3 checks passed
@infiniteregrets infiniteregrets deleted the err-fix branch December 23, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants