-
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
Merged
k8s-ci-robot
merged 10 commits into
kubernetes-sigs:master
from
chansuke:return_err_insteadof_log
Oct 27, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7f3334c
hotfix: return error instead of log at `FromMapAndOption`
chansuke 5eb100c
chore: show error message
chansuke 1849ddf
hotfix: use correct function
chansuke c8172de
hotix: use `t.Helper()` and fix `t *testing.T order
chansuke 18ba44d
hotfix: wrapt the error of `FromMapAndOption`
chansuke 6752985
hotfix: meaningful message for an error
chansuke da28bfa
hotfix: summarize in one line
chansuke 6cd6816
hotfix: fix the abandoned error and show meaningful message
chansuke 54b6056
hotfix: start with helper function
chansuke aa7984c
Keep TODO comment
chansuke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,12 @@ func (rf *Factory) Hasher() ifc.KustHasher { | |
|
||
// FromMap returns a new instance of Resource. | ||
func (rf *Factory) FromMap(m map[string]interface{}) *Resource { | ||
return rf.FromMapAndOption(m, nil) | ||
res, err := rf.FromMapAndOption(m, nil) | ||
if err != nil { | ||
// TODO: return err instead of log. | ||
log.Fatalf("failed to create resource from map: %v", err) | ||
} | ||
return res | ||
} | ||
|
||
// FromMapWithName returns a new instance with the given "original" name. | ||
|
@@ -52,19 +57,22 @@ func (rf *Factory) FromMapWithName(n string, m map[string]interface{}) *Resource | |
|
||
// FromMapWithNamespaceAndName returns a new instance with the given "original" namespace. | ||
func (rf *Factory) FromMapWithNamespaceAndName(ns string, n string, m map[string]interface{}) *Resource { | ||
r := rf.FromMapAndOption(m, nil) | ||
r, err := rf.FromMapAndOption(m, nil) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
} | ||
return r.setPreviousId(ns, n, r.GetKind()) | ||
} | ||
|
||
// FromMapAndOption returns a new instance of Resource with given options. | ||
func (rf *Factory) FromMapAndOption( | ||
m map[string]interface{}, args *types.GeneratorArgs) *Resource { | ||
m map[string]interface{}, args *types.GeneratorArgs) (*Resource, error) { | ||
n, err := yaml.FromMap(m) | ||
if err != nil { | ||
// TODO: return err instead of log. | ||
log.Fatal(err) | ||
return nil, fmt.Errorf("failed to convert map to YAML node: %w", err) | ||
} | ||
return rf.makeOne(n, args) | ||
return rf.makeOne(n, args), nil | ||
} | ||
|
||
// makeOne returns a new instance of Resource. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 meanFromMap
andFromMapWithNamespaceAndName
should the error, instead of doinglog.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?
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