{"record":{"id":"d315029ab8851a00","repo":"karatelabs/karate","slug":"argumentslist-must-be-an-iterable-object","errorCode":null,"errorMessage":"argumentsList must be an iterable object","messagePattern":"argumentsList must be an iterable object","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsReflect.java","lineNumber":121,"sourceCode":"        Object thisArg = args.length >= 2 ? args[1] : Terms.UNDEFINED;\n        Object[] cArgs = listToArray(args.length >= 3 ? args[2] : null);\n        if (context instanceof CoreContext cc) {\n            cc.thisObject = thisArg;\n        }\n        return target.call(context, cArgs);\n    }\n\n    private static Object[] listToArray(Object value) {\n        if (value == null || value == Terms.UNDEFINED) {\n            return new Object[0];\n        }\n        if (value instanceof List<?> list) {\n            return list.toArray();\n        }\n        if (value instanceof Object[] arr) {\n            return arr;\n        }\n        throw JsErrorException.typeError(\"argumentsList must be an iterable object\");\n    }\n\n}\n","sourceCodeStart":103,"sourceCodeEnd":125,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsReflect.java#L103-L125","documentation":"The third argument of Reflect.construct/Reflect.apply (argumentsList) must be array-like: a List, an Object[], or null/undefined (which becomes an empty list). Karate's listToArray throws this TypeError for any other value — a plain string, number, or non-iterable object. Note the check is structural (List/Object[]) rather than a generic JS-iterable walk, so some iterable-but-not-array values are rejected.","triggerScenarios":"Reflect.apply(fn, this, 'abc'); Reflect.construct(C, 5); passing a Map/Set or other non-array iterable as the argument list; passing a JS object like {0:'a', length:1} that would be array-like in real JS but is not a List here.","commonSituations":"Forgetting to wrap a single argument in an array (Reflect.apply(f, null, arg) instead of [arg]); spread from a non-array iterable; porting code that used array-likes (arguments objects, NodeLists) that are not represented as arrays in Karate.","solutions":["Wrap the arguments in an actual array: Reflect.apply(f, this, [a, b])","Convert the value to an array first with Array.from(...) or [...iterable]","If arguments may be absent, pass undefined/null explicitly rather than a non-array value"],"exampleFix":"// before\nReflect.apply(fn, this, 'someArg');\n// after\nReflect.apply(fn, this, ['someArg']);","handlingStrategy":"validation","validationCode":"function asArgList(v) {\n  if (v == null) return [];\n  if (Array.isArray(v)) return v;\n  throw new Error('argumentsList must be an array');\n}\nReflect.apply(fn, thisArg, asArgList(rawArgs));","typeGuard":"const isArgList = v => v == null || Array.isArray(v);\nif (!isArgList(argList)) throw new Error('pass a real array as argumentsList');","tryCatchPattern":"try {\n  return Reflect.construct(C, args);\n} catch (e) {\n  if (String(e.message).includes('argumentsList')) {\n    throw new Error('argumentsList must be an array; got: ' + typeof args);\n  }\n  throw e;\n}","preventionTips":["Always wrap the argument list in an array literal, even for a single argument","Convert iterables with Array.from(...) before passing","Never pass strings/numbers/objects as the third argument","Treat the third parameter as strictly array-or-undefined in your API layer"],"tags":["javascript","reflect","typeerror","arguments-list"],"backgroundTag":"invalid-argument-format","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}