larksuite/cli · error
expected exactly %d items for %s, got %d
Error message
expected exactly %d items for %s, got %d
What it means
For fixed-size array targets (e.g. [2]string tuples used by fixed-arity API params), convertReflectValue enforces exact length and reports 'expected exactly N items for <type>, got M' when the raw list length differs.
Source
Thrown at shortcuts/common/typed_binder.go:218
return nil, err
}
return json.RawMessage(encoded), nil
}
if target.Kind() == reflect.Pointer {
value, err := convertReflectValue(raw, target.Elem())
if err != nil {
return nil, err
}
pointer := reflect.New(target.Elem())
pointer.Elem().Set(reflect.ValueOf(value))
return pointer.Interface(), nil
}
if target.Kind() == reflect.Array || target.Kind() == reflect.Slice {
if rawValue.Kind() != reflect.Array && rawValue.Kind() != reflect.Slice {
return nil, fmt.Errorf("expected list, got %T", raw)
}
if target.Kind() == reflect.Array && rawValue.Len() != target.Len() {
return nil, fmt.Errorf("expected exactly %d items for %s, got %d", target.Len(), target, rawValue.Len())
}
result := reflect.MakeSlice(reflect.SliceOf(target.Elem()), rawValue.Len(), rawValue.Len())
for i := 0; i < rawValue.Len(); i++ {
value, err := convertReflectValue(rawValue.Index(i).Interface(), target.Elem())
if err != nil {
return nil, err
}
result.Index(i).Set(reflect.ValueOf(value))
}
if target.Kind() == reflect.Array {
array := reflect.New(target).Elem()
reflect.Copy(array, result)
return array.Interface(), nil
}
return result.Convert(target).Interface(), nil
}
if rawValue.Type().ConvertibleTo(target) {
converted := reflect.New(target).Elem()View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Count elements against the required length shown in the error's target type (e.g. [2]string)
- Add missing or remove extra elements to reach the exact count
- Use null placeholders if the API allows optional tuple slots
Example fix
// before --range '["2024-01-01"]' // after --range '["2024-01-01","2024-12-31"]'
Defensive patterns
Strategy: validation
Validate before calling
const v = JSON.parse(raw); if (v.length !== 2) throw new Error('exactly 2 items required') Type guard
func hasLen(s string, n int) bool { var v []any; if json.Unmarshal([]byte(s), &v) != nil { return false }; return len(v) == n } Try / catch
if strings.Contains(err.Error(), "expected exactly") { /* parse the required count from the message and pad/trim the input */ } Prevention
- Read the target array type (e.g. [2]string) from the error or schema output
- Validate tuple length before invoking
- Use null placeholders only if the API schema permits them
When it happens
Trigger: Supplying fewer or more elements than the fixed array length, e.g. a 2-element tuple field given '["a"]' or '["a","b","c"]'.
Common situations: API requiring paired values (e.g. [key, value] or [start, end]) where the user passes only one; misunderstanding fixed-arity schema fields.
Related errors
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/6d08e0ec753b2040.
Report an issue: GitHub.