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

Add error codes #457

Merged
merged 30 commits into from
May 10, 2021
Merged

Add error codes #457

merged 30 commits into from
May 10, 2021

Conversation

JakeDawkins
Copy link
Contributor

@JakeDawkins JakeDawkins commented Apr 16, 2021

This PR adds usable error codes, and associates them with all errors that are handled by Rover.

By usable, I mean there's a new rover explain <CODE> command to explain a single error code

I took inspiration for the explanations themselves being in markdown from https://github.com/rust-lang/rust/blob/master/compiler/rustc_error_codes/src/error_codes.rs

We use termimad to do some basic formatting on the markdown explanations, which also gives us some flexibility to make wrapping tables, etc in our explanations. The only odd thing is that it doesn't support markdown links, so those are just printed as markdown

There are also changes to build.rs that iterate over all files in the codes dir and prints their contents to a errors docs for a reference page

rover explain E001

rover git:(jake/error-codes-coding-errors-code) cargo run -- explain E001
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/rover explain E001`
E001

This error occurs when the expected JSON response from a GraphQL endpoint can't
be deserialized.

This is most likely caused by an invalid endpoint or headers, causing the
server to return something that is not JSON (like an HTML error page).

Try running the command again with `--log trace` to see what the GraphQL
endpoint is responding with.

If this error occurs on a command interacting with the Apollo Registry, please
[open an issue](https://github.com/apollographql/rover/issues/new?body=Error%20E001%0A%0ADescribe%20your%20issue%20or%20question%20here&labels=triage)
and let us know!

Copy link
Contributor

@EverlastingBugstopper EverlastingBugstopper left a comment

Choose a reason for hiding this comment

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

This is looking good! I really like the idea of having the errors be in markdown so that we can have some error reference pages in the docs (perfect for SEO on running into errors!) Agree that for printing them out maybe we should try pretty printing the markdown :)

src/command/explain.rs Outdated Show resolved Hide resolved
src/command/explain.rs Outdated Show resolved Hide resolved
src/command/explain.rs Outdated Show resolved Hide resolved
src/error/metadata/code.rs Outdated Show resolved Hide resolved
src/error/metadata/code.rs Show resolved Hide resolved
src/error/metadata/code.rs Outdated Show resolved Hide resolved
src/error/metadata/mod.rs Outdated Show resolved Hide resolved
JakeDawkins and others added 2 commits April 21, 2021 09:27
Co-authored-by: Avery Harnish <avery@apollographql.com>
@JakeDawkins
Copy link
Contributor Author

Since termimad doesn't support markdown links, I decided to replace them with... regex 😬 Let me know if this is terrible, and we can figure out something else.

I'm replacing the markdown urls like [this](https://google.com) with this (https://google.com) to make them a little more readable. I'm also painting them cyan right now to indicate they're urls and to give a little visual separation.

image

Copy link
Contributor

@EverlastingBugstopper EverlastingBugstopper left a comment

Choose a reason for hiding this comment

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

looking good!

src/command/output.rs Outdated Show resolved Hide resolved
src/command/output.rs Outdated Show resolved Hide resolved
src/error/metadata/code.rs Show resolved Hide resolved
@JakeDawkins JakeDawkins added this to the May 11 - GA milestone Apr 28, 2021
@JakeDawkins JakeDawkins added the feature 🎉 new commands, flags, functionality, and improved error messages label Apr 28, 2021
Copy link
Member

@lrlna lrlna left a comment

Choose a reason for hiding this comment

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

This is in a really good shape. I absolutely love the rover explain command, this will be so handy!

Left a few comments about the Code API which may perhaps help with its usage.

src/command/output.rs Outdated Show resolved Hide resolved
src/command/explain.rs Outdated Show resolved Hide resolved
src/error/metadata/code.rs Show resolved Hide resolved
src/error/metadata/code.rs Outdated Show resolved Hide resolved
@JakeDawkins JakeDawkins self-assigned this May 3, 2021
@JakeDawkins JakeDawkins changed the title [WIP] Add error codes Add error codes May 5, 2021
@JakeDawkins JakeDawkins marked this pull request as ready for review May 5, 2021 12:52
@JakeDawkins JakeDawkins added the docs 📝 improvements or additions to docs on the docs site label May 5, 2021
@JakeDawkins JakeDawkins linked an issue May 5, 2021 that may be closed by this pull request
Copy link
Member

@lrlna lrlna left a comment

Choose a reason for hiding this comment

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

LGTM!

build.rs Outdated Show resolved Hide resolved
Comment on lines +283 to +284
.filter_map(Result::ok)
.filter(|e| !e.file_type().unwrap().is_dir());
Copy link
Contributor

Choose a reason for hiding this comment

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

should we maybe error here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We definitely could 🤷‍♂️ Especially since this is at buildtime. I just left it as the simpler option in the meantime. Do you think I should change that?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah since it's at build time i think maybe we should error here so we don't commit something that doesn't work, i imagine filtering out the errors could end up with some head scratches if something goes wrong

Copy link
Member

Choose a reason for hiding this comment

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

I am going to keep this as is for now and we can get it to error in an xtask refactor.

build.rs Outdated Show resolved Hide resolved
src/error/metadata/codes/E023.md Outdated Show resolved Hide resolved
src/error/metadata/mod.rs Outdated Show resolved Hide resolved
@lrlna lrlna merged commit 54536a5 into main May 10, 2021
@lrlna lrlna deleted the jake/error-codes-coding-errors-code branch May 10, 2021 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs 📝 improvements or additions to docs on the docs site feature 🎉 new commands, flags, functionality, and improved error messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

errors: create error status codes
3 participants