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

Return exit code 1 even if stop on error is enabled #142

Merged
merged 3 commits into from
Apr 11, 2022

Conversation

pballandras
Copy link
Contributor

Currently

When the option stop on error is set to true in the config, the first error encountered is returned and we exit with code 1.

When the option stop on error is set to false in the config, the errors are logged as errors, but since they don't bubble up after the execution, we exit with 0.

Proposed change

Nothing changes when the option stop on error is set to true in the config.

When the option stop on error is set to false in the config, we record errors as they occur, and return all of them at once to the command that initiated them. Since we are returning an error, the program will exit with code 1.

@pballandras pballandras requested review from a team April 8, 2022 13:34
Comment on lines +36 to +37
SilenceUsage: true,
SilenceErrors: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes it so when returning an error from a command, we don't:

  1. Show the usage string
  2. We tell the command we'll handle ourselves the errors coming from child commands

@@ -6,6 +6,7 @@ import (
"github.com/coveooss/credentials-sync/credentials"
"github.com/coveooss/credentials-sync/logger"
"github.com/coveooss/credentials-sync/targets"
"github.com/hashicorp/go-multierror"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gives us a struct multierror that makes it possible to aggregate errors and that pretty print them for us.
e.g.

// printing
print(aMultiErrorWith4Errors)
// output 
4 errors occurred:
        * lol une erreur ici
        * lol une erreur ici
        * lol une erreur ici
        * lol une erreur ici

sync/config.go Outdated
@@ -50,12 +51,15 @@ func (config *Configuration) Sync() error {
for _, target := range allTargets {
go config.initTarget(target, creds, initChannel)
}
// This will later become a multierror object or stay nil, this is intended
var error_accumulator error
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure that this code base uses camelCase for variables. At least from the code around this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup facepalms with a python

sync/config.go Outdated
Comment on lines 54 to 55
// This will later become a multierror object or stay nil, this is intended
var error_accumulator error
Copy link
Contributor

Choose a reason for hiding this comment

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

What is intended here? The error type? If that's the case, I'd clarify this in the comment and explain why.

When people are going to be reading this code, I think that they'll be asking "Why is it this way?" and not "Did you intend for that to be this way?".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the comment 🚀

@pballandras pballandras merged commit 820b879 into main Apr 11, 2022
@pballandras pballandras deleted the fix/finish-healthy-syncs-before-erroring-out branch April 11, 2022 15:27
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.

None yet

4 participants