{"record":{"id":"6d08e0ec753b2040","repo":"larksuite/cli","slug":"expected-exactly-d-items-for-s-got-d","errorCode":null,"errorMessage":"expected exactly %d items for %s, got %d","messagePattern":"expected exactly (.+?) items for (.+?), got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/common/typed_binder.go","lineNumber":218,"sourceCode":"\t\t\treturn nil, err\n\t\t}\n\t\treturn json.RawMessage(encoded), nil\n\t}\n\tif target.Kind() == reflect.Pointer {\n\t\tvalue, err := convertReflectValue(raw, target.Elem())\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tpointer := reflect.New(target.Elem())\n\t\tpointer.Elem().Set(reflect.ValueOf(value))\n\t\treturn pointer.Interface(), nil\n\t}\n\tif target.Kind() == reflect.Array || target.Kind() == reflect.Slice {\n\t\tif rawValue.Kind() != reflect.Array && rawValue.Kind() != reflect.Slice {\n\t\t\treturn nil, fmt.Errorf(\"expected list, got %T\", raw)\n\t\t}\n\t\tif target.Kind() == reflect.Array && rawValue.Len() != target.Len() {\n\t\t\treturn nil, fmt.Errorf(\"expected exactly %d items for %s, got %d\", target.Len(), target, rawValue.Len())\n\t\t}\n\t\tresult := reflect.MakeSlice(reflect.SliceOf(target.Elem()), rawValue.Len(), rawValue.Len())\n\t\tfor i := 0; i < rawValue.Len(); i++ {\n\t\t\tvalue, err := convertReflectValue(rawValue.Index(i).Interface(), target.Elem())\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tresult.Index(i).Set(reflect.ValueOf(value))\n\t\t}\n\t\tif target.Kind() == reflect.Array {\n\t\t\tarray := reflect.New(target).Elem()\n\t\t\treflect.Copy(array, result)\n\t\t\treturn array.Interface(), nil\n\t\t}\n\t\treturn result.Convert(target).Interface(), nil\n\t}\n\tif rawValue.Type().ConvertibleTo(target) {\n\t\tconverted := reflect.New(target).Elem()","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/common/typed_binder.go#L200-L236","documentation":"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.","triggerScenarios":"Supplying fewer or more elements than the fixed array length, e.g. a 2-element tuple field given '[\"a\"]' or '[\"a\",\"b\",\"c\"]'.","commonSituations":"API requiring paired values (e.g. [key, value] or [start, end]) where the user passes only one; misunderstanding fixed-arity schema fields.","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"],"exampleFix":"// before\n--range '[\"2024-01-01\"]'\n// after\n--range '[\"2024-01-01\",\"2024-12-31\"]'","handlingStrategy":"validation","validationCode":"const v = JSON.parse(raw); if (v.length !== 2) throw new Error('exactly 2 items required')","typeGuard":"func hasLen(s string, n int) bool { var v []any; if json.Unmarshal([]byte(s), &v) != nil { return false }; return len(v) == n }","tryCatchPattern":"if strings.Contains(err.Error(), \"expected exactly\") { /* parse the required count from the message and pad/trim the input */ }","preventionTips":["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"],"tags":["type-conversion","array-length","input-binding"],"backgroundTag":"array-length-mismatch","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}