forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: give error message if
write()
cb called twice
Otherwise, this condition would result in an error that just reads `cb is not a function`, and which additionally could have lost stack trace context through a `process.nextTick()` call. PR-URL: nodejs#19510 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const { Writable } = require('stream'); | ||
|
||
{ | ||
// Sync + Sync | ||
const writable = new Writable({ | ||
write: common.mustCall((buf, enc, cb) => { | ||
cb(); | ||
common.expectsError(cb, { | ||
code: 'ERR_MULTIPLE_CALLBACK', | ||
type: Error | ||
}); | ||
}) | ||
}); | ||
writable.write('hi'); | ||
} | ||
|
||
{ | ||
// Sync + Async | ||
const writable = new Writable({ | ||
write: common.mustCall((buf, enc, cb) => { | ||
cb(); | ||
process.nextTick(() => { | ||
common.expectsError(cb, { | ||
code: 'ERR_MULTIPLE_CALLBACK', | ||
type: Error | ||
}); | ||
}); | ||
}) | ||
}); | ||
writable.write('hi'); | ||
} | ||
|
||
{ | ||
// Async + Async | ||
const writable = new Writable({ | ||
write: common.mustCall((buf, enc, cb) => { | ||
process.nextTick(cb); | ||
process.nextTick(() => { | ||
common.expectsError(cb, { | ||
code: 'ERR_MULTIPLE_CALLBACK', | ||
type: Error | ||
}); | ||
}); | ||
}) | ||
}); | ||
writable.write('hi'); | ||
} |