Skip to content

fix(core): propagate rejections and pre-start errors in halted pipes - #1563

Open
asxxb wants to merge 1 commit into
google:mainfrom
asxxb:main
Open

asxxb wants to merge 1 commit into
google:mainfrom
asxxb:main

Conversation

@asxxb

@asxxb asxxb commented Nov 29, 2026

Copy link
Copy Markdown

Problem

When piping a halted ProcessPromise ($({ halt: true })) into another ProcessPromise, ProcessPromise._pipe() placed this.catch((e) => dest.break(e.exitCode, e.signal, e.cause)) exclusively inside the else branch of if (this.isHalted()).

As a result, when a halted upstream process failed:

  1. dest.break(...) was never called, so the downstream process saw clean EOF and resolved with exitCode: 0 (silently masking upstream failures).
  2. The upstream ProcessPromise rejection had no .catch() handler, causing an UnhandledPromiseRejection in Node.js even when awaiting the pipeline inside try/catch.

Additionally, pre-start failures (such as a missing cwd or rejected async command interpolation) exposed three related edge cases:

  • fill() accessed this._zurk!.store[source] directly, throwing TypeError: Cannot read properties of null (reading 'store') when _zurk was never initialized.
  • Pre-cb() failures in run() finalized without emitting 'end' on $.ee, leaving piped streams open.
  • break() returned early if dest was still 'halted', and threw Trying to kill a process without creating one. if dest was 'running' before dest.child was spawned (e.g., while resolving async command interpolation).

Minimal reproduction

const $h = $({ halt: true })

// Before: resolves with exitCode 0 and triggers UnhandledPromiseRejection
await $h`exit 1`.pipe`cat`.run()

Changes

  • src/core.ts
    • Attach this.catch((e) => check() && dest.break(e.exitCode, e.signal, e.cause)) unconditionally for ProcessPromise targets in _pipe(), and guard the halted start listener with check() && dest.run() so unpipe()d targets are neither started nor broken.
    • Update ProcessPromise.break() to no-op when settled, call this.kill(signal).catch(noop) when this.child exists, and finalize unstarted/pre-child destinations directly with a ProcessOutput carrying the upstream exitCode, signal, and cause (preserving nothrow()).
    • Emit 'end' on $.ee for pre-cb() failures in run(), skip cb() if already settled, and keep cb() in its own try/catch.
    • Guard fill() with this._zurk?.store[source] || [].
  • test/core.test.js
    • Add regression test propagates rejection from halted and pre-start failing processes covering halted pipelines, unpipe(), multiple upstream sources, nothrow, pre-start missing-cwd failures, pre-child async destinations, and asserting zero unhandledRejection events.
  • build/core.cjs, .size-limit.json
    • Rebuilt bundle and updated size-limit entries (npm run build && npm run build:size-limit).

Verification

  • npm run build
  • npm run test:types
  • npm run test:size
  • npm run fmt:check
  • npm run test:license
  • npm run test:circular
  • node --test --test-name-pattern="pipe\(\)" test/core.test.js (28/28 passed)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant