sindresorhus / nano-spawn

Tiny process execution for humans — a better child_process
MIT License
437 stars 6 forks source link

Improve `promise.stdout` error handling #39

Closed ehmicky closed 2 months ago

ehmicky commented 2 months ago

This PR improves some details when iterating over promise.stdout or promise.stderr.

Users are expected to do for await (const line of nanoSpawn(...).stdout), i.e. are not likely to await the subprocess promise. Therefore, when the for await loop stops due to break or an exception, the loop must await the subprocess promise. Otherwise, if the subprocess fails, it will result in an unhandled rejected promise. Note: this is also what Execa is doing.

Also, when the for await loop stops due to break, the subprocess stdout/stderr stream should not be destroyed, since the break might not indicate any problem nor failure.

Finally, this PR improves the related tests, and adds more of them.