From 4c855019d912982cd30f2c940e0908892c68410b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Tue, 10 Sep 2024 15:57:20 -0300 Subject: [PATCH] fix: Calling `err.Error()` on nil error causes panic (#579) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel GraƱa Co-authored-by: Thomas Poignant --- providers/go-feature-flag/pkg/controller/goff_api.go | 5 +++-- providers/go-feature-flag/pkg/provider.go | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/providers/go-feature-flag/pkg/controller/goff_api.go b/providers/go-feature-flag/pkg/controller/goff_api.go index 317e46b0b..cf900a95d 100644 --- a/providers/go-feature-flag/pkg/controller/goff_api.go +++ b/providers/go-feature-flag/pkg/controller/goff_api.go @@ -4,10 +4,11 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/open-feature/go-sdk-contrib/providers/go-feature-flag/pkg/model" "net/http" "net/url" "path" + + "github.com/open-feature/go-sdk-contrib/providers/go-feature-flag/pkg/model" ) type GoFeatureFlagApiOptions struct { @@ -104,7 +105,7 @@ func (g *GoFeatureFlagAPI) ConfigurationHasChanged() (ConfigurationChangeStatus, case http.StatusNotModified: return FlagConfigurationNotChanged, nil default: - return ErrorConfigurationChange, err + return ErrorConfigurationChange, fmt.Errorf("request failed with status: %v", response.Status) } } diff --git a/providers/go-feature-flag/pkg/provider.go b/providers/go-feature-flag/pkg/provider.go index 559bd22e5..1ecacf9b0 100644 --- a/providers/go-feature-flag/pkg/provider.go +++ b/providers/go-feature-flag/pkg/provider.go @@ -3,12 +3,13 @@ package gofeatureflag import ( "context" "fmt" + "time" + "github.com/open-feature/go-sdk-contrib/providers/go-feature-flag/pkg/controller" "github.com/open-feature/go-sdk-contrib/providers/go-feature-flag/pkg/hook" "github.com/open-feature/go-sdk-contrib/providers/go-feature-flag/pkg/util" "github.com/open-feature/go-sdk-contrib/providers/ofrep" of "github.com/open-feature/go-sdk/openfeature" - "time" ) const providerName = "GO Feature Flag" @@ -245,7 +246,8 @@ func (p *Provider) startPolling(pollingInterval time.Duration) { p.events <- of.Event{ ProviderName: providerName, EventType: of.ProviderStale, ProviderEventDetails: of.ProviderEventDetails{ - Message: "Impossible to check configuration change " + err.Error()}, + Message: fmt.Sprintf("Impossible to check configuration change: %s", err), + }, } } }