-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
hotfix: return error instead of log at FromMapAndOption
#5381
hotfix: return error instead of log at FromMapAndOption
#5381
Conversation
This PR has multiple commits, and the default merge method is: merge. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Welcome @chansuke! |
Hi @chansuke. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
also seems like the tests are failing can you go ahead and fix them |
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 think we should avoid the fatal
function.
But we are currently using log.Fatal()
, and we can fix it with the next PR.
https://github.com/kubernetes-sigs/kustomize/pull/5381/files#diff-9041e805f414eb549e8ebcf4f2b82c1f40403e3ebe86a1f67f9c76718bd91797L65
I think this PR is moving forward to the first step and is useful for kustomize.
@chansuke
Thanks for your contribution!
I added any comments, Could you check it?
err = expected.Append(makeConfigMapOptions(rf, name, c.behavior, !c.needsHash)) | ||
config, err := makeConfigMapOptions(rf, name, c.behavior, !c.needsHash) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) |
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 think the unexpected error
message is confusing.
Could you add any meaningful message?
api/resmap/reswrangler_test.go
Outdated
})) | ||
}) | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) |
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.
same here
api/resmap/reswrangler_test.go
Outdated
})) | ||
}) | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) |
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.
same too
api/resmap/reswrangler_test.go
Outdated
assert.NoError(t, w.AbsorbAll(makeMap2(types.BehaviorMerge))) | ||
}) | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) |
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.
same too
api/resmap/reswrangler_test.go
Outdated
err = w.AbsorbAll(w2) | ||
assert.Error(t, err) |
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.
If you can, Could you summarize it in one line?
api/resource/factory.go
Outdated
return rf.FromMapAndOption(m, nil) | ||
res, err := rf.FromMapAndOption(m, nil) | ||
if err != nil { | ||
log.Fatal("Option must not be null") |
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.
It looks like this line abandoned a non-nil error.
Could you make a change to print the substance of the returned error?
api/resource/factory.go
Outdated
r := rf.FromMapAndOption(m, nil) | ||
r, err := rf.FromMapAndOption(m, nil) | ||
if err != nil { | ||
log.Fatal("Option must not be null") |
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.
same here
@koba1t I appreciate your feedback and review! I will go fix them. |
171d984
to
6cd6816
Compare
@koba1t I've addressed your comments and made the necessary changes. Please take a look 🙏
|
/ok-to-test |
/label tide/merge-method-squash |
Thanks for the fix! /lgtm @natasha41575 |
@koba1t Thanks! I'll take a look on friday |
return rf.FromMapAndOption(m, nil) | ||
res, err := rf.FromMapAndOption(m, nil) | ||
if err != nil { | ||
log.Fatalf("failed to create resource from map: %v", err) |
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 think the idea of the TODO was to return the error all the way to the top, e.g. completely avoid the use of log.Fatalf
for this. That would mean FromMap
and FromMapWithNamespaceAndName
should the error, instead of doing log.Fatalf
here, and likewise all the way up.
Looks like you and @koba1t already had a discussion about potentially doing that in a follow-up PR. I think that's fine to do in a followup, but in that case could we keep the TODO here?
if err != nil {
// TODO: return err instead of log.
log.Fatalf("failed to create resource from map: %v", err)
}
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.
@natasha41575 Thank you for the review. Yes, I will put the TODO comment again
r := rf.FromMapAndOption(m, nil) | ||
r, err := rf.FromMapAndOption(m, nil) | ||
if err != nil { | ||
log.Fatalf("failed to create resource from map: %v", err) |
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.
same here
@natasha41575 Updated the code. Please take a look. |
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.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: chansuke, natasha41575 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…-sigs#5381) * hotfix: return error instead of log at `FromMapAndOption` * chore: show error message * hotfix: use correct function * hotix: use `t.Helper()` and fix `t *testing.T order * hotfix: wrapt the error of `FromMapAndOption` * hotfix: meaningful message for an error * hotfix: summarize in one line * hotfix: fix the abandoned error and show meaningful message * hotfix: start with helper function * Keep TODO comment
Make FromMapAndOption to return error.