MCPcopy Create free account
hub / github.com/github/gh-aw / checkMaxField

Function checkMaxField

pkg/workflow/safe_outputs_max_validation.go:29–46  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
29func 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).

Callers 1

validateSafeOutputsMaxFunction · 0.85

Calls 4

isExpressionFunction · 0.85
isInvalidMaxValueFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected