Closed
Description
- Version: v12.13.1
- Platform: Windows 10 pro 64-bit
- Subsystem: readline
The iterator resulting from the readline.createInterface()
should reject on the first iteration when the underlying input stream raises an error event. In fact, it is missing the error handling.
We can observe this problem regarding the example of processLineByLine() when we try to invoke the processLineByLine()
for an absent file.
Even if we wrap the for await (const line of rl) {…}
in a try/catch
block we are unable to handle the error and the program finishes with:
events.js:187
throw er; // Unhandled 'error' event
^
Error: ENOENT: no such file or directory, open 'input.txt'
Emitted 'error' event on ReadStream instance at:
at internal/fs/streams.js:120:12
at FSReqCallback.oncomplete (fs.js:146:23) {...}
A couple of workarounds has been discussed in the Stackoverflow question How to handle error from fs readline.Interface async iterator and jfriend00 proposes some alternatives to detour the problem: https://stackoverflow.com/a/59217504/1140754