-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Open
Description
Version
24.0.1
Platform
Darwin ... 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6030 arm64
Linux ... 6.8.0-39-generic #39-Ubuntu SMP PREEMPT_DYNAMIC Sat Jul 6 02:50:39 UTC 2024 aarch64 GNU/Linux
Subsystem
readline
What steps will reproduce the bug?
The following code creates a dummy fs that throws an error on the fs.close() call.
This error can be caught with events.once() when using the fs directly.
When using the fs together with readline, the error is not caught by events.once().
import { once } from 'events'
import { createReadStream } from 'fs'
import { createInterface } from 'readline'
let position = 0
const myDummyFilesystem = {
read: (fd, buffer, offset, len, pos, cb) => { buffer.write("A\n"); cb(null, ((position += 2) <= 10) ? 2 : 0, buffer) },
close: (x, cb) => { cb(new Error("close failed")) },
open: (name, flags, mode, cb) => { cb(undefined, 42) }
}
async function bad() {
const file = createReadStream('app.js', { fs: myDummyFilesystem })
const rl = createInterface({ input: file })
let lineNr = 0
rl.on('line', (line) => console.log(`bad ${++lineNr} ${line}`))
await once(rl, 'close') // DOES NOT CATCH Error of the fs.close() CALL
}
async function good() {
const file = createReadStream('app.js', { fs: myDummyFilesystem })
let lineNr = 0
file.on('data', (line) => console.log(`good ..`))
await once(file, 'close') // CATCHES Error of the fs.close() CALL
}
await (good().catch(e => console.error("nice first catch", e)))
position = 0
bad().catch(e => console.error("nice second catch", e))How often does it reproduce? Is there a required condition?
always
What is the expected behavior? Why is that the expected behavior?
the await once(...) also catches the error on fs.close()
What do you see instead?
Unhandled Exception error
Additional information
No response
Metadata
Metadata
Assignees
Labels
No labels