mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
fix: return error instead of log.Fatalf() (#5625)
* fix: return error instead of log.Fatalf() * chore: add meaningful message to error output * chore: add meaningful message to fatal function
This commit is contained in:
@@ -41,28 +41,26 @@ func (rf *Factory) Hasher() ifc.KustHasher {
|
||||
}
|
||||
|
||||
// FromMap returns a new instance of Resource.
|
||||
func (rf *Factory) FromMap(m map[string]interface{}) *Resource {
|
||||
func (rf *Factory) FromMap(m map[string]interface{}) (*Resource, error) {
|
||||
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 nil, fmt.Errorf("failed to create resource from map: %w", err)
|
||||
}
|
||||
return res
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// FromMapWithName returns a new instance with the given "original" name.
|
||||
func (rf *Factory) FromMapWithName(n string, m map[string]interface{}) *Resource {
|
||||
func (rf *Factory) FromMapWithName(n string, m map[string]interface{}) (*Resource, error) {
|
||||
return rf.FromMapWithNamespaceAndName(resid.DefaultNamespace, n, m)
|
||||
}
|
||||
|
||||
// FromMapWithNamespaceAndName returns a new instance with the given "original" namespace.
|
||||
func (rf *Factory) FromMapWithNamespaceAndName(ns string, n string, m map[string]interface{}) *Resource {
|
||||
func (rf *Factory) FromMapWithNamespaceAndName(ns string, n string, m map[string]interface{}) (*Resource, error) {
|
||||
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)
|
||||
return nil, fmt.Errorf("failed to create resource from map: %w", err)
|
||||
}
|
||||
return r.setPreviousId(ns, n, r.GetKind())
|
||||
return r.setPreviousId(ns, n, r.GetKind()), nil
|
||||
}
|
||||
|
||||
// FromMapAndOption returns a new instance of Resource with given options.
|
||||
|
||||
Reference in New Issue
Block a user