Repository navigation
provide the ability to modify the prefix of error reporting and ignor… - #11639
Conversation
|
Example output: |
|
this seems like turning human readable messages into an API, which we don't want to do. |
|
|
||
| if errs := cfg.Action.WithMessage(fmt.Sprintf("Creating router %s", cfg.Name), "created").Run(list, namespace); len(errs) > 0 { | ||
| levelFilter := func(e error) string { | ||
| if match, _ := regexp.MatchString("serviceaccounts|rolebinding.*already exists", e.Error()); match { |
There was a problem hiding this comment.
could be anything that you'd consider less fragile, a check against IsAlreadyExists and then looking for SA for example.
There was a problem hiding this comment.
Yes, I think you have a well qualified error here, and a IsAlreadyExists check from the api would work. Definitely better.
other suggestions? I considered just iterating through the list of returned errors in the command itself and parsing them out that way however that doesn't improve any of the output. It will still show "error:" and "Failure". |
|
Thinking about this a bit more, could you elaborate a bit on your stance here? This is not touching any part of the message other than the prefix which was hardcoded to "error" and the ability to control reporting "Success" vs "Failure" of a bulk action. Most of that is already controllable with the |
|
[test] |
|
|
||
| if errs := cfg.Action.WithMessage(fmt.Sprintf("Creating router %s", cfg.Name), "created").Run(list, namespace); len(errs) > 0 { | ||
| levelFilter := func(e error) string { | ||
| if match, _ := regexp.MatchString("serviceaccounts|rolebinding.*already exists", e.Error()); match { |
There was a problem hiding this comment.
Yes, I think you have a well qualified error here, and a IsAlreadyExists check from the api would work. Definitely better.
|
|
||
| // ErrorFilterFunc provides a way to filter errors during the Bulk.Run. This may be used in conjunction with | ||
| // BulkAction.WithMessageAndPrefix if you are reporting items as warnings. | ||
| type ErrorFilterFunc func(e error) bool |
There was a problem hiding this comment.
Not very clear to me what the return value means, does a true means "filter out" or "keep it"? Mention it in the doc, or call it IgnoreErrorFunc, BypassErrorFunc, FatalErrorFunc, or something similar.
|
|
||
| func (b BulkAction) WithMessage(action, individual string) Runner { | ||
| // PrefixFilter allows customization of the prefix that will be printed for any error that occurs in the BulkAction. | ||
| type PrefixFilter func(e error) string |
There was a problem hiding this comment.
Maybe PrefixForError, ErrorPrefixMsg, or something similar?
9d20a01 to
ba6d3aa
Compare
|
@fabianofranz updated naming and docs based on feedback. PTAL |
f0c89df to
9d08c22
Compare
| // only ignore SA/RB errors if we were creating the service account and | ||
| // check for their specific type/name combination | ||
| if errors.IsAlreadyExists(e) && createServiceAccount { | ||
| if strings.Contains(e.Error(), "serviceaccounts") && strings.Contains(e.Error(), cfg.ServiceAccount) { |
There was a problem hiding this comment.
I think the error you get here is a errors.StatusError, in which case you would have Kind and Name well structured to perform this comparison. Can you confirm?
There was a problem hiding this comment.
it is. Updated to use StatusError's Details and broke it out into a method since it was getting a bit long with casts and nil checks.
9d08c22 to
4b35045
Compare
fabianofranz
left a comment
There was a problem hiding this comment.
Minor nit otherwise LGTM, @liggitt anything else?
| } | ||
|
|
||
| if errs := cfg.Action.WithMessage(fmt.Sprintf("Creating router %s", cfg.Name), "created").Run(list, namespace); len(errs) > 0 { | ||
| levelFilter := func(e error) string { |
4b35045 to
cfd133f
Compare
…e some errors in cmd operations
cfd133f to
08423a7
Compare
|
Evaluated for origin test up to 08423a7 |
|
continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10864/) (Base Commit: 11d3928) |
|
[merge] |
2 similar comments
|
[merge] |
|
[merge] |
|
Evaluated for origin merge up to 08423a7 |
|
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10920/) (Base Commit: 751085f) (Image: devenv-rhel7_5289) |
…e some errors in cmd operations
@ffranz - proposed for https://bugzilla.redhat.com/show_bug.cgi?id=1332432
Provides the ability to not include errors during run which in turn controls Failure or Success message output. Additionally allows customization of the prefix used during the bulk action so you can choose to report warnings, hints, or anything else in the message.
@openshift/cli-review