larksuite/cli · error

encoding repeated only supports string arrays

Error message

encoding repeated only supports string arrays

What it means

encoding=repeated additionally requires the slice/array element to be a string: repeated flag occurrences always yield strings, and the library does not coerce them to other element types. validateInputCLI inspects indirectType(field.valueType).Elem().Kind() and rejects non-string elements.

Source

Thrown at shortcuts/common/typed_compile_args.go:315

		}
	}
	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")
		}
	case typedEncodingJSON:
		if kind != reflect.Slice && kind != reflect.Array && kind != reflect.Struct && kind != reflect.Map && kind != reflect.Interface {
			return fmt.Errorf("encoding json requires array, object, oneOf, or custom JSON input")

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Use encoding=comma_or_repeated, which supports string or integer arrays
  2. Change the element type to string and parse integers in the shortcut code
  3. Remove the encoding if the field is not a string array

Example fix

// before
cli:"--ids,encoding=repeated" // []int64 field
// after
cli:"--ids,encoding=comma_or_repeated"
Defensive patterns

Strategy: validation

Validate before calling

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

Try / catch

if err := compileInput(...); err != nil {
	if strings.Contains(err.Error(), "encoding repeated only supports string arrays") {
		// switch to comma_or_repeated for integer arrays, or make elements string
	}
	return err
}

Prevention

When it happens

Trigger: Declaring encoding=repeated on a field like []int, []bool, or []*string - the kind is a slice/array but the element is not reflect.String. Raised by compileInput during shortcut compilation.

Common situations: Repeating flags for integer lists (use comma_or_repeated instead); having changed the element type from string to int without changing the encoding; assuming repeated performs numeric parsing.

Related errors


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