larksuite/cli · error

%sarray has %d items, maximum is %d

Error message

%sarray has %d items, maximum is %d

What it means

Schema validation error from collectSchemaErrors: an array flag value has more items than the schema's `maxItems`. The intermediate error is wrapped by validateFlagAgainstSchema into a typed flag validation error with a --print-schema hint.

Source

Thrown at shortcuts/sheets/flag_schema_validate.go:388

	// Numeric bounds — only checked when value is a number (type mismatch
	// already reported above). Apply to both `number` and `integer` types.
	if num, ok := value.(float64); ok {
		if schema.Minimum != nil && num < *schema.Minimum {
			c.add(fmt.Errorf("%svalue %v is below minimum %v", pathPrefix(path), num, *schema.Minimum)) //nolint:forbidigo // intermediate error; validateFlagAgainstSchema wraps it into a typed flag validation error with a --print-schema hint
		}
		if schema.Maximum != nil && num > *schema.Maximum {
			c.add(fmt.Errorf("%svalue %v is above maximum %v", pathPrefix(path), num, *schema.Maximum)) //nolint:forbidigo // intermediate error; validateFlagAgainstSchema wraps it into a typed flag validation error with a --print-schema hint
		}
	}

	// Array length bounds — only checked when value is an array.
	if arr, ok := value.([]interface{}); ok {
		if schema.MinItems != nil && len(arr) < *schema.MinItems {
			c.add(fmt.Errorf("%sarray has %d items, minimum is %d", pathPrefix(path), len(arr), *schema.MinItems)) //nolint:forbidigo // intermediate error; validateFlagAgainstSchema wraps it into a typed flag validation error with a --print-schema hint
		}
		if schema.MaxItems != nil && len(arr) > *schema.MaxItems {
			c.add(fmt.Errorf("%sarray has %d items, maximum is %d", pathPrefix(path), len(arr), *schema.MaxItems)) //nolint:forbidigo // intermediate error; validateFlagAgainstSchema wraps it into a typed flag validation error with a --print-schema hint
		}
	}

	if len(schema.Enum) > 0 {
		matched := false
		for _, allowed := range schema.Enum {
			if jsonEqual(allowed, value) {
				matched = true
				break
			}
		}
		if !matched {
			msg := fmt.Sprintf("%svalue %s is not in enum %s",
				pathPrefix(path), formatJSONValue(value), formatEnum(schema.Enum))
			if hint := suggestEnumForError(value, schema.Enum); hint != "" {
				msg += fmt.Sprintf(` (did you mean %q?)`, hint)
			}
			c.add(fmt.Errorf("%s", msg)) //nolint:forbidigo // intermediate error; validateFlagAgainstSchema wraps it into a typed flag validation error with a --print-schema hint

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Trim or split the array so it has at most the schema's maximum items.
  2. Chunk the work into multiple invocations, each within maxItems.
  3. Check the bound via --print-schema and enforce it in your batch builder.

Example fix

// before
--rows '[...500 items...]'  // maxItems is 100
// after
// chunk into 5 calls of --rows '[...100 items...]'
Defensive patterns

Strategy: validation

Validate before calling

const maxItems = 100; // from schema
if (Array.isArray(arr) && arr.length > maxItems) {
  throw new Error(`array exceeds ${maxItems} items: ${arr.length}`);
}

Type guard

function hasAtMostItems(v: unknown, max: number): v is unknown[] {
  return Array.isArray(v) && v.length <= max;
}

Prevention

When it happens

Trigger: Passing a JSON array flag exceeding `maxItems`, e.g. a batch update capped at 100 rows receiving 500.

Common situations: Batching large exports in one call; API version changes lowering the allowed batch size; concatenating multiple datasets without splitting.

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


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/51fb470cf6ba2ce1. Report an issue: GitHub.