{"record":{"id":"3a276590445fd24d","repo":"karatelabs/karate","slug":"is-not-iterable","errorCode":null,"errorMessage":" is not iterable","messagePattern":" is not iterable","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsArrayConstructor.java","lineNumber":98,"sourceCode":"                index++;\n            }\n            // Spec §23.1.2.1 returns an Array exotic — wrap so\n            // `Array.from(...).constructor === Array` and\n            // `Array.from(...) instanceof Array` hold.\n            return new JsArray(results);\n        }\n        // Array-like fallback: map-of-string-keys with `length` (e.g. {0: 'a', 1: 'b', length: 2}).\n        if (source instanceof Map) {\n            JsArray array = JsArray.toArray((Map<String, Object>) source);\n            int index = 0;\n            for (Object v : array.list) {\n                Object mapped = mapFn == null ? v : mapFn.call(context, new Object[]{v, index});\n                results.add(mapped);\n                index++;\n            }\n            return new JsArray(results);\n        }\n        throw JsErrorException.typeError(source + \" is not iterable\");\n    }\n\n    private Object isArray(Object[] args) {\n        return args.length > 0 && args[0] instanceof List;\n    }\n\n    private Object of(Object[] args) {\n        // Spec §23.1.2.3 — return an Array. Wrap in JsArray (mutable copy)\n        // so callers can {@code push}/{@code pop} and so\n        // {@code Array.of(...).constructor === Array} holds; the bare\n        // {@code Arrays.asList} would be a fixed-size Java List.\n        List<Object> list = new ArrayList<>(args.length);\n        for (Object arg : args) list.add(arg);\n        return new JsArray(list);\n    }\n\n}\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsArrayConstructor.java#L80-L116","documentation":"Array.from falls back to an array-like length-walk only when appropriate; if the source has no @@iterator and is not array-like, this TypeError names the value and states it is not iterable. Per spec, values without an iterator protocol and without length cannot be converted to arrays.","triggerScenarios":"Array.from({a:1}) (plain object, no length, no iterator); Array.from(42); Array.from(true); Array.from on a custom object that lacks Symbol.iterator.","commonSituations":"Assuming all objects are array-like; iterating over a map-like structure without converting it; passing class instances that never implemented the iterable interface.","solutions":["Wrap the value: use Object.values(obj) or Object.entries(obj) for plain objects","Make the source iterable by implementing @@iterator, or spread a real array","Guard with a check that the value has Symbol.iterator or a numeric length before calling Array.from"],"exampleFix":"// before\nArray.from(config); // plain object -> not iterable\n// after\nArray.from(Object.values(config));","handlingStrategy":"type-guard","validationCode":"function isIterable(x) { return x != null && typeof x[Symbol.iterator] === 'function'; }","typeGuard":"function isIterable(x) { return x != null && typeof x[Symbol.iterator] === 'function'; }","tryCatchPattern":"try { var a = Array.from(src); } catch (e) { if (String(e).indexOf('is not iterable') !== -1) { a = Object.values(src || {}); } else { throw e; } }","preventionTips":["Verify the source implements @@iterator or has a numeric length","Use Object.values/Object.entries for plain objects","Add iterable support (Symbol.iterator) to custom classes you feed to Array.from"],"tags":["javascript","array","type-error","iterable"],"backgroundTag":"type-mismatch","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"}