checkMaxField validates a single safe-output max field value. Returns an error if the max value is invalid (0 or negative, except -1). Returns nil if the max pointer is nil, the value is an expression, or is valid.
(toolName string, maxPtr *string)
| 27 | // Returns an error if the max value is invalid (0 or negative, except -1). |
| 28 | // Returns nil if the max pointer is nil, the value is an expression, or is valid. |
| 29 | func checkMaxField(toolName string, maxPtr *string) error { |
| 30 | if maxPtr == nil || isExpression(*maxPtr) { |
| 31 | return nil |
| 32 | } |
| 33 | n, err := strconv.Atoi(*maxPtr) |
| 34 | if err != nil { |
| 35 | return nil |
| 36 | } |
| 37 | if isInvalidMaxValue(n) { |
| 38 | toolDisplayName := strings.ReplaceAll(toolName, "_", "-") |
| 39 | safeOutputsMaxValidationLog.Printf("Invalid max value %d for %s", n, toolDisplayName) |
| 40 | return fmt.Errorf( |
| 41 | "safe-outputs.%s: max must be a positive integer or -1 (unlimited), got %d%s", |
| 42 | toolDisplayName, n, maxInvalidErrSuffix, |
| 43 | ) |
| 44 | } |
| 45 | return nil |
| 46 | } |
| 47 | |
| 48 | // validateSafeOutputsMax validates that all max fields in safe-outputs configs hold valid values. |
| 49 | // Valid values are positive integers (n > 0) or -1 (unlimited per spec). |
no test coverage detected