Skip to content

Commit

Permalink
Fix error messages (#5542)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjngx authored May 14, 2024
1 parent 95fc147 commit ba976cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions internal/configs/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions internal/configs/parsing_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba976cb

Please sign in to comment.