larksuite/cli · error
schema maxItems: %w
Error message
schema maxItems: %w
What it means
parseSchemaTag validates each `schema` struct tag token on typed shortcut argument fields. The `maxItems` token must be a non-negative integer; if parseNonnegativeInt rejects the value, the underlying error is wrapped with the "schema maxItems: " prefix and compilation of the field fails.
Source
Thrown at shortcuts/common/typed_compile_args.go:487
return result, fmt.Errorf("schema minimum: %w", err)
}
result.minimum = &v
case "maximum":
v, err := parseFiniteFloat(value)
if err != nil {
return result, fmt.Errorf("schema maximum: %w", err)
}
result.maximum = &v
case "minItems":
v, err := parseNonnegativeInt(value)
if err != nil {
return result, fmt.Errorf("schema minItems: %w", err)
}
result.minItems = &v
case "maxItems":
v, err := parseNonnegativeInt(value)
if err != nil {
return result, fmt.Errorf("schema maxItems: %w", err)
}
result.maxItems = &v
default:
return result, fmt.Errorf("unknown schema token %q", key)
}
}
if result.required == result.optional {
return result, fmt.Errorf("schema must declare exactly one of required or optional")
}
if result.required && result.defaultValue.Set {
return result, fmt.Errorf("required input cannot declare default")
}
if result.nullable != nil && *result.nullable && !isNilCapable(valueType) {
return result, fmt.Errorf("nullable requires a nil-capable Go type")
}
if result.minLength != nil && result.maxLength != nil && *result.minLength > *result.maxLength {
return result, fmt.Errorf("minLength exceeds maxLength")
}View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Use a plain non-negative integer for maxItems, e.g. schema:"optional;maxItems=100".
- Ensure there are no spaces or units inside the tag value.
- Drop the maxItems token if no upper bound is required.
Example fix
// before Tags []string `schema:"optional;maxItems=0x10"` // after Tags []string `schema:"optional;maxItems=16"`
Defensive patterns
Strategy: validation
Validate before calling
func validMaxItems(tag string) bool {
for _, tok := range strings.Split(tag, ";") {
if k, v, ok := strings.Cut(tok, "="); ok && k == "maxItems" {
n, err := strconv.Atoi(v)
return err == nil && n >= 0
}
}
return true
} Prevention
- Use decimal integers only; no units or hex.
- Keep maxItems >= minItems when both are present.
- Add a unit test compiling every shortcut input struct to catch bad tags early.
When it happens
Trigger: A field tag such as `schema:"optional;maxItems=ten"`, `maxItems=` (empty value), `maxItems=-5`, or a value that overflows the integer parser, encountered while compiling a shortcut input struct.
Common situations: Typos or accidental units in the tag (e.g. "maxItems=10 items"), negative limits copied from other configs, or malformed tags after manual editing.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- schema minItems: %w
- schema must declare exactly one of required or optional
- unknown schema token %q
- required input cannot declare default
- nullable requires a nil-capable Go type
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/a75585752c4bc9c1.
Report an issue: GitHub.