diff --git a/cmd/karma/autocomplete.go b/cmd/karma/autocomplete.go index b3244eab3..273ab61ac 100644 --- a/cmd/karma/autocomplete.go +++ b/cmd/karma/autocomplete.go @@ -45,11 +45,7 @@ func knownLabelNames(c *gin.Context) { sort.Strings(acData) } - data, err := json.Marshal(acData) - if err != nil { - log.Error(err.Error()) - panic(err) - } + data, _ = json.Marshal(acData) apiCache.Set(cacheKey, data, time.Second*15) @@ -80,11 +76,7 @@ func knownLabelValues(c *gin.Context) { values := alertmanager.DedupKnownLabelValues(name) sort.Strings(values) - data, err := json.Marshal(values) - if err != nil { - log.Error(err.Error()) - panic(err) - } + data, _ = json.Marshal(values) apiCache.Set(cacheKey, data, time.Second*15) diff --git a/cmd/karma/proxy_test.go b/cmd/karma/proxy_test.go index 8b6e31a88..c35a4697e 100644 --- a/cmd/karma/proxy_test.go +++ b/cmd/karma/proxy_test.go @@ -1206,3 +1206,22 @@ func TestProxySilenceACL(t *testing.T) { }) } } + +func TestNewAlertmanagerProxyWithInvalidURL(t *testing.T) { + am := alertmanager.Alertmanager{URI: "%gh&%ij"} + proxy, err := NewAlertmanagerProxy(&am) + if err == nil { + t.Errorf("NewAlertmanagerProxy didn't return any error") + } + if proxy != nil { + t.Errorf("NewAlertmanagerProxy returned a proxy instance: %v", proxy) + } +} + +func TestSetupRouterProxyHandlersWithInvalidURL(t *testing.T) { + am := alertmanager.Alertmanager{URI: "%gh&%ij"} + err := setupRouterProxyHandlers(nil, &am) + if err == nil { + t.Errorf("setupRouterProxyHandlers didn't return any error") + } +}