larksuite/cli · error

encoding repeated does not allow nullable/nonnullable

Error message

encoding repeated does not allow nullable/nonnullable

What it means

Fields with repeated encoding cannot also declare nullable/nonnullable behavior (field.nullable set). Repeated occurrence counting already defines presence semantics (zero occurrences means empty/absent), so an explicit nullability declaration is redundant and disallowed.

Source

Thrown at shortcuts/common/typed_compile_args.go:318

	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")
		}
		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")

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Remove the nullable/nonnullable declaration from the repeated field - an empty list already represents absence
  2. If you need an explicit null sentinel, switch the field to encoding=json where nullability is supported
  3. Keep repeated encoding only on plain []string fields with no nullability clause

Example fix

// before
cli:"--tags,encoding=repeated,nullable"
// after
cli:"--tags,encoding=repeated"
Defensive patterns

Strategy: validation

Validate before calling

func repeatedNoNullable(cliEncoding, nullableDecl string) error {
	if cliEncoding == "repeated" && nullableDecl != "" {
		return errors.New("repeated fields cannot declare nullable")
	}
	return nil
}

Try / catch

if err := compileInput(...); err != nil {
	if strings.Contains(err.Error(), "encoding repeated does not allow nullable") {
		// drop nullable/nonnullable from the repeated field
	}
	return err
}

Prevention

When it happens

Trigger: Combining encoding=repeated with a nullable or nonnullable declaration in the cli tag or InputField (field.nullable != nil). Raised by compileInput during shortcut compilation.

Common situations: Copy-pasting a nullable=json field definition and changing the encoding to repeated without removing nullable/nonnullable; trying to distinguish 'flag absent' from 'explicitly null' on a repeated field; template-generated fields that always emit nullable.

Related errors


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