{"record":{"id":"f4f55729c17ddba4","repo":"Hmbown/CodeWhale","slug":"task-expected-an-options-object","errorCode":null,"errorMessage":"task(): expected an options object","messagePattern":"task\\(\\): expected an options object","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/workflow-js/src/vm.rs","lineNumber":1526,"sourceCode":"  // The failure ledger for one fan-out, attached to the resolved array as a\n  // non-enumerable `errors` property. Non-enumerable and non-index, so the\n  // array's contents, length, and JSON encoding are byte-identical to before:\n  // `results.filter(Boolean)` still works, and a script that wants to know\n  // WHY a slot is null can now ask instead of guessing.\n  const attachSlotErrors = (results, errors) => {\n    errors.sort((a, b) => a.index - b.index);\n    Object.defineProperty(results, \"errors\", {\n      value: Object.freeze(errors.map((entry) => Object.freeze(entry))),\n      enumerable: false,\n      configurable: false,\n      writable: false,\n    });\n    return results;\n  };\n\n  globalThis.task = async (opts) => {\n    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    }","sourceCodeStart":1508,"sourceCodeEnd":1544,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/workflow-js/src/vm.rs#L1508-L1544","documentation":"Thrown by the prelude's `globalThis.task` in vm.rs when the first argument is null or not an object. `task(opts)` requires an options object that is serialized to the host via `hostTask(JSON.stringify(opts))`; anything else (null, a string, a number, undefined) is rejected with this TypeError before the host call.","triggerScenarios":"Calling `task()` with no arguments, `task(null)`, `task(\"kind\")`, or `task(42)`; also calling with a non-object like an array-of-thunks where an options object was expected.","commonSituations":"Confusing task() with parallel()'s thunk API; forgetting the options wrapper around the task kind; a refactor that changed the call signature.","solutions":["Pass an options object: `task({ kind: \"...\", ...params })`.","If you intended to run several functions, use `parallel(thunks)` instead of task().","Wrap primitives in the expected envelope shape before calling.","Check the call site for a missing object literal (e.g. `task(\"fetch\")` → `task({ kind: \"fetch\" })`)."],"exampleFix":"// before\nconst data = await task(\"fetch_user\", userId);\n// after\nconst data = await task({ kind: \"fetch_user\", userId });","handlingStrategy":"type-guard","validationCode":"function assertTaskOpts(opts) {\n  if (opts === null || typeof opts !== 'object') {\n    throw new TypeError('task() requires an options object like { kind: \"...\" }');\n  }\n}","typeGuard":"function isTaskOpts(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  const result = await task(opts);\n} catch (e) {\n  if (e instanceof TypeError && e.message === 'task(): expected an options object') {\n    console.error('wrap task parameters in an object: task({ kind, ...params })');\n  } else throw e;\n}","preventionTips":["Always pass an object literal as the sole task() argument.","Remember task() takes one options object; extra params go inside it.","Use parallel() for thunks, task() for host work — do not mix signatures.","Type-check call sites in your editor before running workflows."],"tags":["workflow","argument-validation","typeerror"],"backgroundTag":"invalid-constructor-argument","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"}