larksuite/cli · error

encoding repeated requires an array or slice

Error message

encoding repeated requires an array or slice

What it means

The repeated encoding means the flag may be supplied multiple times, one value per occurrence; that model only makes sense for Go slices or arrays. validateInputCLI rejects encoding=repeated on any other kind (scalar, struct, map, interface) with this message.

Source

Thrown at shortcuts/common/typed_compile_args.go:312

		}
		if (len(seenSources) > 1) && indirectKind(field.valueType) != reflect.String && field.cli.Encoding != typedEncodingJSON {
			return fmt.Errorf("file/stdin sources require string input or encoding=json")
		}
	}
	kind := indirectKind(field.valueType)
	if kind == reflect.Slice || kind == reflect.Array || kind == reflect.Struct || kind == reflect.Map || kind == reflect.Interface {
		if field.cli.Encoding == "" {
			return fmt.Errorf("%s input must explicitly declare CLI encoding", kind)
		}
	}
	switch field.cli.Encoding {
	case "":
		if kind == reflect.Slice || kind == reflect.Array || kind == reflect.Struct || kind == reflect.Map || kind == reflect.Interface {
			return fmt.Errorf("complex input requires encoding")
		}
	case typedEncodingRepeated:
		if kind != reflect.Slice && kind != reflect.Array {
			return fmt.Errorf("encoding repeated requires an array or slice")
		}
		if indirectType(field.valueType).Elem().Kind() != reflect.String {
			return fmt.Errorf("encoding repeated only supports string arrays")
		}
		if field.nullable != nil {
			return fmt.Errorf("encoding repeated does not allow nullable/nonnullable")
		}
	case typedEncodingCommaOrRepeated:
		if kind != reflect.Slice && kind != reflect.Array {
			return fmt.Errorf("encoding comma_or_repeated requires an array or slice")
		}
		elementKind := indirectType(field.valueType).Elem().Kind()
		if elementKind != reflect.String && !isIntegerKind(elementKind) {
			return fmt.Errorf("encoding comma_or_repeated only supports string or integer arrays")
		}
		if field.nullable != nil {
			return fmt.Errorf("encoding comma_or_repeated does not allow nullable/nonnullable")
		}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Change the field type to []string (or an array) to keep encoding repeated
  2. Switch the encoding to comma_or_repeated if you want a single comma-separated value or repeated occurrences for string/integer arrays
  3. Remove the encoding if the field is scalar and should be set once

Example fix

// before
cli:"--name,encoding=repeated" // string field
// after
cli:"--name" // scalar set once, or []string with encoding=repeated
Defensive patterns

Strategy: validation

Validate before calling

func repeatedEncodingOK(t reflect.Type) bool {
	for t.Kind() == reflect.Ptr {
		t = t.Elem()
	}
	return t.Kind() == reflect.Slice || t.Kind() == reflect.Array
}

Try / catch

if err := compileInput(...); err != nil {
	if strings.Contains(err.Error(), "encoding repeated requires") {
		// change the field to []string or drop encoding=repeated
	}
	return err
}

Prevention

When it happens

Trigger: Declaring an input field with Encoding "repeated" whose valueType is not a slice or array - e.g. a string, int, or struct field. Raised by compileInput during shortcut compilation.

Common situations: Copying the encoding=repeated fragment from a []string field onto a scalar field; wanting comma-separated parsing (which is comma_or_repeated, not repeated) but selecting repeated; refactoring a field's type from []string to string without dropping the encoding.

Related errors


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