-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Don't exit on error when condition is not met #327
Conversation
Signed-off-by: Olivier Vernin <olivier@vernin.me>
Signed-off-by: Olivier Vernin <olivier@vernin.me>
Signed-off-by: Olivier Vernin <olivier@vernin.me>
pkg/core/reports/main.go
Outdated
successCounter++ | ||
} else if report.Result == result.FAILURE { | ||
} else if strings.Compare(report.Result, result.FAILURE) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have used successives if
instead of these else if
but it's maybe just me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chaing the if
means that you could allow entering different conditions (if your wrote it with an error), while the else if
ensures that only one of the block is executed.
However this chain of else if
should clearly use a switch
/ case
instruction (please note that strings.Compare
should also be replaced by a simple ==
comparison as it's targeted for a lexicographic comparison which is not really performant - https://pkg.go.dev/strings#Compare )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In these cases, I prefer to set an "error" flag at the beginning, then successives "if" (cancelling the flag), and finally return an error if the flag is still set. Not sure how it could enter differents "if" in this actual case.
Easier to (re)read/comprehend than "if...elseif" or "switch", and (as I understood) a common pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how it could enter differents "if" in this actual case.
If a human messes up the instructions in theif
. Happens a lot when a major refactoring or a bumpy merge conflict happen, while a "switch" would statically ensure this.
I cannot propose a suggestion here (the diff is split), but here is a proposal to give an idea:
switch report.Result {
case "result.SUCCESS":
successCounter++
case "result.FAILURE":
failedCounter++
case "result.ATTENTION":
changedCounter++
case "result.SKIPPED":
skippedCounter++
default:
logrus.Infof("Unknown report result %q with named %q.", report.Result, report.Name)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review, the switch syntax makes more sense here.
Regarding the syntax to compare strings, it appears that string1 == string2
is better than using strings.Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, it sounds good for me for the use case.
There is a chain of else if
+ Strings.compare that should be changed to a swicth / case
and string equalities==
though
pkg/core/reports/main.go
Outdated
successCounter++ | ||
} else if report.Result == result.FAILURE { | ||
} else if strings.Compare(report.Result, result.FAILURE) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chaing the if
means that you could allow entering different conditions (if your wrote it with an error), while the else if
ensures that only one of the block is executed.
However this chain of else if
should clearly use a switch
/ case
instruction (please note that strings.Compare
should also be replaced by a simple ==
comparison as it's targeted for a lexicographic comparison which is not really performant - https://pkg.go.dev/strings#Compare )
Signed-off-by: Olivier Vernin <olivier@vernin.me>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Signed-off-by: Olivier Vernin olivier@vernin.me
Don't exit on error when condition is not met
Fix #291
This pull request introduces a new final result type which is "skipped" which happen when a pipeline run is abort but not due to an error like a condition is not met.
I am modifying the final output message to easily identify those situations
Test
To test this pull request, you can run the following commands:
Additionnal Information
Output
Now
Old