Hmbown/CodeWhale · error · TypeError

pipeline(): expected an array of items

Error message

pipeline(): expected an array of items

What it means

Thrown by the prelude's `globalThis.pipeline` in vm.rs when its first argument is not an array. `pipeline(items, ...stages)` feeds an array of items through stage functions, so a non-array first argument is rejected with this TypeError before any stage runs.

Solutions

  1. Wrap single values in an array: `pipeline([item], stage)`.
  2. Convert non-array iterables: `pipeline(Array.from(items), ...stages)`.
  3. Confirm the first argument is the items array and stages follow as extra arguments.
  4. Pass `[]` for an empty pipeline run instead of null/undefined.

Example fix

// before
const out = await pipeline(order, normalize, enrich);
// after
const out = await pipeline([order], normalize, enrich);
Defensive patterns

Strategy: type-guard

Validate before calling

function assertItems(items) {
  if (!Array.isArray(items)) {
    throw new TypeError('pipeline() requires an array of items; wrap a single item in [item]');
  }
}

Type guard

function isItemArray(v) {
  return Array.isArray(v);
}

Try / catch

try {
  const out = await pipeline(items, ...stages);
} catch (e) {
  if (e instanceof TypeError && e.message === 'pipeline(): expected an array of items') {
    console.error('pipeline([items...], ...stages) — first argument must be an array');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `pipeline(item)` with a single item instead of `[item]`; passing an object, string, or non-array iterable as items; argument order mistakes when using the options overload `pipeline(items, { stages: [...], mode })`.

Common situations: Forgetting to wrap a lone item in an array; passing a Map/Set or generator result directly; refactoring from parallel() to pipeline() with mismatched argument shapes.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/f32a41dcab870cc9. Report an issue: GitHub.

Appendix: source

Thrown at crates/workflow-js/src/vm.rs:1616

      // A fan-out where nothing survived is a dead fan-out, not resilience.
      // The default stays ergonomic (the array still resolves) but the run
      // log says so in one line an operator can grep for, and the structured
      // event below lets the host status classifier refuse to call such a
      // run a plain success.
      if (results.length > 0 && errors.length === results.length) {
        hostLog(
          "parallel(): every slot failed (" + errors.length + " of " + results.length +
          "); no work survived this fan-out"
        );
        hostEverySlotFailed("parallel", errors.length, results.length);
      }
      return attachSlotErrors(results, errors);
    });
  };

  globalThis.pipeline = (items, ...stages) => {
    if (!Array.isArray(items)) {
      throw new TypeError("pipeline(): expected an array of items");
    }
    if (items.length > MAX_ITEMS) {
      throw new Error("pipeline(): max " + MAX_ITEMS + " items per call");
    }
    // Options overload: pipeline(items, { stages: [...], mode: "fail-fast" }).
    let mode = "settled";
    if (
      stages.length === 1 &&
      stages[0] !== null &&
      typeof stages[0] === "object" &&
      Array.isArray(stages[0].stages)
    ) {
      mode = slotMode("pipeline", stages[0]);
      stages = stages[0].stages;
    }
    const failFast = mode === "fail-fast";
    const partial = mode === "partial";
    const errors = [];

View on GitHub (pinned to 73e0f67d83)