From d45484b0fb02f5435250eece72a7f3e964c16f4f Mon Sep 17 00:00:00 2001 From: Jakub Jarosz <99677300+jjngx@users.noreply.github.com> Date: Tue, 14 May 2024 17:29:54 +0100 Subject: [PATCH] Fix error messages (#5542) --- internal/configs/annotations.go | 6 +++--- internal/configs/parsing_helpers.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/configs/annotations.go b/internal/configs/annotations.go index 97447f2849..b0eb8d2291 100644 --- a/internal/configs/annotations.go +++ b/internal/configs/annotations.go @@ -453,7 +453,7 @@ func parseRateLimitAnnotations(annotations map[string]string, cfgParams *ConfigP errors := make([]error, 0) if requestRateLimit, exists := annotations["nginx.org/limit-req-rate"]; exists { if rate, err := ParseRequestRate(requestRateLimit); err != nil { - errors = append(errors, fmt.Errorf("Ingress %s/%s: Invalid value for nginx.org/limit-req-rate: got %s: %w", context.GetNamespace(), context.GetName(), requestRateLimit, err)) + errors = append(errors, fmt.Errorf("ingress %s/%s: invalid value for nginx.org/limit-req-rate: got %s: %w", context.GetNamespace(), context.GetName(), requestRateLimit, err)) } else { cfgParams.LimitReqRate = rate } @@ -463,7 +463,7 @@ func parseRateLimitAnnotations(annotations map[string]string, cfgParams *ConfigP } if requestRateZoneSize, exists := annotations["nginx.org/limit-req-zone-size"]; exists { if size, err := ParseSize(requestRateZoneSize); err != nil { - errors = append(errors, fmt.Errorf("Ingress %s/%s: Invalid value for nginx.org/limit-req-zone-size: got %s: %w", context.GetNamespace(), context.GetName(), requestRateZoneSize, err)) + errors = append(errors, fmt.Errorf("ingress %s/%s: invalid value for nginx.org/limit-req-zone-size: got %s: %w", context.GetNamespace(), context.GetName(), requestRateZoneSize, err)) } else { cfgParams.LimitReqZoneSize = size } @@ -498,7 +498,7 @@ func parseRateLimitAnnotations(annotations map[string]string, cfgParams *ConfigP } if requestRateLogLevel, exists := annotations["nginx.org/limit-req-log-level"]; exists { if !slices.Contains([]string{"info", "notice", "warn", "error"}, requestRateLogLevel) { - errors = append(errors, fmt.Errorf("Ingress %s/%s: Invalid value for nginx.org/limit-req-log-level: got %s", context.GetNamespace(), context.GetName(), requestRateLogLevel)) + errors = append(errors, fmt.Errorf("ingress %s/%s: invalid value for nginx.org/limit-req-log-level: got %s", context.GetNamespace(), context.GetName(), requestRateLogLevel)) } else { cfgParams.LimitReqLogLevel = requestRateLogLevel } diff --git a/internal/configs/parsing_helpers.go b/internal/configs/parsing_helpers.go index dc9645e9f3..494b19e1e6 100644 --- a/internal/configs/parsing_helpers.go +++ b/internal/configs/parsing_helpers.go @@ -250,16 +250,16 @@ func ParseRequestRate(s string) (string, error) { match := rateRegexp.FindStringSubmatch(s) if match == nil { - return "", errors.New("String does not match rate-pattern: ^(\\d+)(r/s|r/m)$") + return "", errors.New("string does not match rate-pattern: ^(\\d+)(r/s|r/m)$") } number, err := strconv.Atoi(match[1]) if err != nil { - return "", errors.New("String does not match rate-pattern") + return "", errors.New("string does not match rate-pattern") } if number <= 0 { - return "", errors.New("Rate must be >0") + return "", errors.New("rate must be >0") } return s, nil