Радар на почту

Почему обработчик ошибок Transform в Node.js недостаточен

DEV · 16.11.2026 · 00:25

В цепочке потоков Node.js важно правильно обрабатывать ошибки и закрывать связанные участники. Пример демонстрирует поведение жизненного цикла с использованием объектного режима.

Читать в источнике

Оригинал

Why a Node.js Transform error listener is not enough

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 buff