{"record":{"id":"fe525006c51340e0","repo":"Hmbown/CodeWhale","slug":"parallel-expected-an-array-of-thunks","errorCode":null,"errorMessage":"parallel(): expected an array of thunks","messagePattern":"parallel\\(\\): expected an array of thunks","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/workflow-js/src/vm.rs","lineNumber":1543,"sourceCode":"    if (opts === null || typeof opts !== \"object\") {\n      throw new TypeError(\"task(): expected an options object\");\n    }\n    const envelope = JSON.parse(await hostTask(JSON.stringify(opts)));\n    if (envelope.error !== undefined) {\n      const err = new Error(envelope.error);\n      // The host always names the kind; a missing one means an envelope this\n      // prelude did not produce, which is not a typed task failure.\n      err.kind = HOST_KINDS.indexOf(envelope.error_kind) !== -1\n        ? envelope.error_kind\n        : SCRIPT_KIND;\n      throw err;\n    }\n    return envelope.value;\n  };\n\n  globalThis.parallel = (thunks, opts) => {\n    if (!Array.isArray(thunks)) {\n      throw new TypeError(\"parallel(): expected an array of thunks\");\n    }\n    if (thunks.length > MAX_ITEMS) {\n      throw new Error(\"parallel(): max \" + MAX_ITEMS + \" items per call\");\n    }\n    const mode = slotMode(\"parallel\", opts);\n    const failFast = mode === \"fail-fast\";\n    const partial = mode === \"partial\";\n    const errors = [];\n    // Returns the slot value, or throws to reject the whole fan-out.\n    const onSlotError = (index, err) => {\n      const kind = taskErrorKind(err);\n      const message = taskErrorText(err);\n      stampKind(err, kind);\n      // Cancellation is the run's deadline in every mode, partial included.\n      if (kind === \"cancelled\") throw err;\n      if (partial) {\n        // Opt-in partial mode: every non-cancellation slot failure becomes a\n        // structured value the script can branch on. It never masquerades as","sourceCodeStart":1525,"sourceCodeEnd":1561,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/workflow-js/src/vm.rs#L1525-L1561","documentation":"Thrown by the prelude's `globalThis.parallel` in vm.rs when its first argument is not an array. `parallel(thunks, opts?)` fans out an array of zero-argument async thunk functions, so a non-array first argument is rejected with this TypeError before any scheduling happens.","triggerScenarios":"Calling `parallel(fn)` with a single thunk instead of `[fn]`; passing an object map or an iterable that is not an Array (e.g. a Set or generator); passing the opts object as the first argument by mistake.","commonSituations":"Forgot to wrap a single callback in array brackets; converted a Map/Set of thunks without Array.from; argument order swapped so opts landed first.","solutions":["Wrap single thunks in an array: `parallel([thunk])`.","Convert other iterables first: `parallel(Array.from(thunkSet))`.","Ensure the argument order is `parallel(thunks, opts)` — the array comes first.","Pass `[]` explicitly when there is nothing to run rather than undefined/null."],"exampleFix":"// before\nconst [r] = await parallel(async () => fetchThing());\n// after\nconst [r] = await parallel([async () => fetchThing()]);","handlingStrategy":"type-guard","validationCode":"function assertThunks(thunks) {\n  if (!Array.isArray(thunks)) {\n    throw new TypeError('parallel() requires an array of thunks; wrap a single thunk in [thunk]');\n  }\n}","typeGuard":"function isThunkArray(v) {\n  return Array.isArray(v) && v.every(t => typeof t === 'function');\n}","tryCatchPattern":"try {\n  const results = await parallel(thunks, opts);\n} catch (e) {\n  if (e instanceof TypeError && e.message === 'parallel(): expected an array of thunks') {\n    console.error('parallel([thunk, ...], opts?) — first argument must be an array');\n  } else throw e;\n}","preventionTips":["Wrap even single thunks in array brackets.","Convert Sets/Maps/generators with Array.from before calling parallel().","Keep argument order (thunks, opts) straight.","Ensure every array element is a zero-argument function."],"tags":["workflow","argument-validation","typeerror"],"backgroundTag":"type-mismatch","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}