From 5e6300cc2ecaa96bc779965009880b58c75a8031 Mon Sep 17 00:00:00 2001 From: hamistao Date: Mon, 13 Jul 2026 10:37:56 -0300 Subject: [PATCH 1/4] Simplify error creation Signed-off-by: hamistao --- pkg/config/operations/operations.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/config/operations/operations.go b/pkg/config/operations/operations.go index 21b48e8e..7f67bed3 100644 --- a/pkg/config/operations/operations.go +++ b/pkg/config/operations/operations.go @@ -2,7 +2,6 @@ package operations import ( "encoding/json" - "errors" "fmt" "sigs.k8s.io/yaml" @@ -42,7 +41,7 @@ func GetValue(keyPath []string, searchMap map[string]any) (any, error) { if len(keyPath) == 1 { keypathvalues, ok := searchMap[keyPath[0]] if !ok { - err = errors.New(fmt.Sprintf("expected key does not exist: %s", keyPath[0])) + err = fmt.Errorf("expected key does not exist: %s", keyPath[0]) } return keypathvalues, err } else { From 6b5330157cea7bcf2be2017b789bfea007db742d Mon Sep 17 00:00:00 2001 From: hamistao Date: Mon, 13 Jul 2026 10:36:42 -0300 Subject: [PATCH 2/4] Improve error on missing config key Signed-off-by: hamistao --- pkg/config/config.go | 5 ++++- pkg/config/operations/operations.go | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 21b995a8..eaa5af73 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -35,7 +35,10 @@ func LoadConfig(key string, config interface{}) { panic(err) } - scoped := all[key] + scoped, ok := all[key] + if !ok { + panic(fmt.Errorf("Key %s not present in provided config", key)) + } scopedString, err := yaml.Marshal(scoped) if err != nil { panic(err) diff --git a/pkg/config/operations/operations.go b/pkg/config/operations/operations.go index 7f67bed3..eee29b8b 100644 --- a/pkg/config/operations/operations.go +++ b/pkg/config/operations/operations.go @@ -65,7 +65,11 @@ func GetValue(keyPath []string, searchMap map[string]any) (any, error) { // LoadObjectFromMap unmarshals a specific key's value into an object func LoadObjectFromMap(key string, config map[string]any, object any) { - keyConfig := config[key] + keyConfig, ok := config[key] + if !ok { + panic(fmt.Errorf("Key %s not present in provided config", key)) + } + scopedString, err := yaml.Marshal(keyConfig) if err != nil { panic(err) From bae3e287e339d17609a8c69d327765d4adaa5197 Mon Sep 17 00:00:00 2001 From: hamistao Date: Mon, 13 Jul 2026 10:35:42 -0300 Subject: [PATCH 3/4] Remove redundant logic Signed-off-by: hamistao --- clients/rancher/v1/client.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/clients/rancher/v1/client.go b/clients/rancher/v1/client.go index 7b99632a..c23cc1f6 100644 --- a/clients/rancher/v1/client.go +++ b/clients/rancher/v1/client.go @@ -131,10 +131,6 @@ func (c *Client) ProxyDownstream(clusterID string) (*Client, error) { updatedOpts.URL = proxyHost baseClient, err := clientbase.NewAPIClient(&updatedOpts) - if err != nil { - return nil, err - } - if err != nil { return nil, fmt.Errorf("failed creating Proxy Client. Backoff error: %v", err) } @@ -219,9 +215,7 @@ func (c *SteveClient) ListAll(params url.Values) (*SteveCollection, error) { resp = next resp.Data = data } - if err != nil { - return resp, err - } + return resp, err } @@ -375,9 +369,7 @@ func (c *NamespacedSteveClient) ListAll(params url.Values) (*SteveCollection, er resp = next resp.Data = data } - if err != nil { - return resp, err - } + return resp, err } From 5c4f0fda89d469a6f3d956b442ab819b414b35ca Mon Sep 17 00:00:00 2001 From: hamistao Date: Wed, 15 Jul 2026 15:40:57 -0300 Subject: [PATCH 4/4] log instead of panic --- pkg/config/config.go | 2 +- pkg/config/operations/operations.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index eaa5af73..9d21cf53 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -37,7 +37,7 @@ func LoadConfig(key string, config interface{}) { scoped, ok := all[key] if !ok { - panic(fmt.Errorf("Key %s not present in provided config", key)) + logrus.Infof("Key %s not present in provided config", key) } scopedString, err := yaml.Marshal(scoped) if err != nil { diff --git a/pkg/config/operations/operations.go b/pkg/config/operations/operations.go index eee29b8b..68f7feff 100644 --- a/pkg/config/operations/operations.go +++ b/pkg/config/operations/operations.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" + "github.com/sirupsen/logrus" "sigs.k8s.io/yaml" ) @@ -67,7 +68,7 @@ func GetValue(keyPath []string, searchMap map[string]any) (any, error) { func LoadObjectFromMap(key string, config map[string]any, object any) { keyConfig, ok := config[key] if !ok { - panic(fmt.Errorf("Key %s not present in provided config", key)) + logrus.Infof("Key %s not present in provided config", key) } scopedString, err := yaml.Marshal(keyConfig)