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

Application level error consumption and handling #186

Merged
merged 1 commit into from
Jan 27, 2021

Conversation

EverlastingBugstopper
Copy link
Contributor

@EverlastingBugstopper EverlastingBugstopper commented Jan 15, 2021

fixes #146

This PR establishes patterns for application-level error handling in Rover by creating the rover::error module. This module exports Result<T, RoverError>, which is used in Rover to exit the application with the proper status code. RoverError is a struct that wraps anyhow::Error and provides contextual information about the error in enums Option<Code> (error codes) and Option<Suggestion> (possible solutions that helps the user troubleshoot). These are wrapped up into a Metadata struct, which can be created from an anyhow::Error. RoverError also has a Display implementation that is used in Rover to display the errors any way we like. I've taken a shot at a default Display implementation here, but I'm very happy to work out the exact details on how it looks like with y'all.

here's an example of an error with a solution:

$ rover config profile show
error: No non-sensitive config found for profile "default"
        Try re-running this command with the '--sensitive' argument

once we add error codes, they will look something like this:

$ rover config profile show
error[E210]: No non-sensitive config found for profile "default"
              Try re-running this command with the '--sensitive' argument

In RoverError's constructor, Code and Solution are created by taking advantage of anyhow::Error::downcast. This allows us to find the underlying Error enum exported by various crates (like houston::HoustonProblem and rover_client::RoverClientError). Here, we can determine the error codes and solutions for various errors with match statements on those library-provided error enums!

I'm hoping this allows us to take a bit of an incremental approach to improving errors, as we see areas for improvement, we can extend our library error types, and adjust their solutions/error codes in rover::error::metadata.


Let's merge this as is if it all looks good and then we can take care of improving individual errors and adding codes/suggestions incrementally.

@EverlastingBugstopper EverlastingBugstopper added this to the 🐣 0.1.0 milestone Jan 15, 2021
@EverlastingBugstopper EverlastingBugstopper changed the title feat(rover-error): initial commit Application level error consumption and handling Jan 21, 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.

If you like, let's pair on this!

crates/rover-error/src/error.rs Outdated Show resolved Hide resolved
crates/rover-error/src/code.rs Outdated Show resolved Hide resolved
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 looks really good, @EverlastingBugstopper. Merge merge merge away!

crates/rover-error/src/error.rs Outdated Show resolved Hide resolved
crates/rover-error/src/metadata/mod.rs Outdated Show resolved Hide resolved
@EverlastingBugstopper EverlastingBugstopper force-pushed the avery/errorerrorerrorerror branch 6 times, most recently from c426244 to 3ecdae8 Compare January 27, 2021 19:55
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.

errors: create a unified Rover error
3 participants