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

cli: api error handling #55

Merged
merged 2 commits into from
Aug 3, 2022
Merged

Conversation

BrunoRosendo
Copy link
Member

closes #16

@BrunoRosendo BrunoRosendo changed the title Api error handling cli: api error handling Jul 29, 2022
utils/errors.go Outdated Show resolved Hide resolved
Copy link
Member

@mdonadoni mdonadoni left a comment

Choose a reason for hiding this comment

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

Works well! It is really unfortunate that we have to rely on reflection to do this, but I don't think we can do otherwise.

Note that we should also use utils.HandleBasicApiError in the logs command.

utils/errors.go Outdated Show resolved Hide resolved
utils/errors.go Outdated Show resolved Hide resolved
@BrunoRosendo BrunoRosendo force-pushed the apiErrorHandling branch 2 times, most recently from 75fa2f5 to 75b0491 Compare August 2, 2022 09:52
cmd/ping.go Outdated Show resolved Hide resolved
@BrunoRosendo
Copy link
Member Author

BrunoRosendo commented Aug 2, 2022

Unfortunately, Cobra's PostRunE does not run when there are errors, so I did the handling in main. For this reason, I had to silence the errors in the root command and print it in main instead

Edit: See spf13/cobra#914 (comment)

utils/errors.go Outdated Show resolved Hide resolved
Copy link
Member

@mdonadoni mdonadoni left a comment

Choose a reason for hiding this comment

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

It's very nice having all the error handling in a single place! Nice job 😄

@mdonadoni mdonadoni merged commit 87e208a into reanahub:master Aug 3, 2022
@BrunoRosendo BrunoRosendo deleted the apiErrorHandling branch August 4, 2022 14:01
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.

cli: improve api client error handling
3 participants