larksuite/cli · error

encoding comma_or_repeated requires an array or slice

Error message

encoding comma_or_repeated requires an array or slice

What it means

validateInputCLI checks each typed input field declared via `cli` tags or InputField.CLI when a shortcut compiles its input struct (compileInput). The `encoding=comma_or_repeated` encoding accepts a CLI value as either a comma-separated list or repeated flags, which only makes sense for array/slice fields. This error means the field carrying that encoding is not a slice or array.

Source

Thrown at shortcuts/common/typed_compile_args.go:322

	}
	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")
		}
		if isNilCapable(field.valueType) && field.nullable == nil && !field.shapeExplicit && !shapeExplicitlyNullable(field.shape) {
			return fmt.Errorf("nil-capable encoding=json input must declare nullable or nonnullable")
		}
	default:
		return fmt.Errorf("unknown CLI encoding %q", field.cli.Encoding)
	}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Change the field type to a slice or array (e.g. []string or []int) to match encoding=comma_or_repeated.
  2. If the field is truly scalar, drop the encoding (plain strings need no encoding) or use a supported encoding for its type.
  3. Check mergeInputSupplement: the encoding may come from InputField.CLI rather than the tag; remove it from whichever source is wrong.

Example fix

// before
Names string `schema:"optional" cli:"encoding=comma_or_repeated"`
// after
Names []string `schema:"optional" cli:"encoding=comma_or_repeated"`
Defensive patterns

Strategy: validation

Validate before calling

func validCommaOrRepeatedEncoding(v any) error {
	t := reflect.TypeOf(v)
	for t != nil && (t.Kind() == reflect.Ptr) { t = t.Elem() }
	if t == nil || (t.Kind() != reflect.Slice && t.Kind() != reflect.Array) {
		return fmt.Errorf("comma_or_repeated needs slice/array, got %v", t)
	}
	return nil
}

Type guard

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

Prevention

When it happens

Trigger: A shortcut input struct declares a non-array field (e.g. `string`, `int`, `map[string]string`) with tag `cli:"encoding=comma_or_repeated"` or sets InputField.CLI.Encoding = "comma_or_repeated"; compileInput then calls validateInputCLI and fails.

Common situations: Copy-pasting a tag from a list-typed field onto a scalar field; renaming a field's Go type from []string to string without removing the encoding; hand-writing InputField.CLI metadata to match another field's encoding.

Related errors


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