A failed Node.js stream chain has two jobs to complete: report the failure and close the connected participants. Those jobs are easy to confuse when a Readable feeds a Transform and then a Writable.
The example below uses object mode to make lifecycle behavior visible. The source emits a small set of values, the Transform uppercases each value until it reaches a chosen failure marker, and the destination records the output it receives. Keeping the fixture in memory avoids file, socket, and buffering details that would obscure the central question.
The important implementation decision is the boundary around the chain. Repeated .pipe() calls connect the stages for data flow. If the Transform fails, an error listener can observe that failure and prevent it from being unhandled. But observing an error is not the same as cleanup: the failed Transform may be destroyed while the source remains readable and the destination remains writable or unfinished.…