GeezerVison is showing github.com — stream: use null for the error argument · nodejs/node@2b32985
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/streams/writable.js +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -497,7 +497,7 @@ function afterWrite(stream, state, count, cb) { | 497 | 497 |
| 498 | 498 | while (count-- > 0) { | 499 | 499 | state.pendingcb--; | 500 | | - cb(); | | 500 | + cb(null); | 501 | 501 | } | 502 | 502 |
| 503 | 503 | if (state.destroyed) { | @@ -640,8 +640,10 @@ Writable.prototype.end = function(chunk, encoding, cb) { | 640 | 640 | } | 641 | 641 |
| 642 | 642 | if (typeof cb === 'function') { | 643 | | - if (err || state.finished) { | | 643 | + if (err) { | 644 | 644 | process.nextTick(cb, err); | | 645 | + } else if (state.finished) { | | 646 | + process.nextTick(cb, null); | 645 | 647 | } else { | 646 | 648 | state[kOnFinished].push(cb); | 647 | 649 | } | @@ -742,7 +744,7 @@ function finish(stream, state) { | 742 | 744 |
| 743 | 745 | const onfinishCallbacks = state[kOnFinished].splice(0); | 744 | 746 | for (let i = 0; i < onfinishCallbacks.length; i++) { | 745 | | - onfinishCallbacks[i](); | | 747 | + onfinishCallbacks[i](null); | 746 | 748 | } | 747 | 749 |
| 748 | 750 | stream.emit('finish'); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-stream-writable-end-cb-error.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,7 +36,7 @@ const stream = require('stream'); | 36 | 36 | let called = false; | 37 | 37 | writable.end('asd', common.mustCall((err) => { | 38 | 38 | called = true; | 39 | | - assert.strictEqual(err, undefined); | | 39 | + assert.strictEqual(err, null); | 40 | 40 | })); | 41 | 41 |
| 42 | 42 | writable.on('error', common.mustCall((err) => { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-stream2-writable.js +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -194,7 +194,8 @@ for (let i = 0; i < chunks.length; i++) { | 194 | 194 | { | 195 | 195 | // Verify write callbacks | 196 | 196 | const callbacks = chunks.map(function(chunk, i) { | 197 | | - return [i, function() { | | 197 | + return [i, function(err) { | | 198 | + assert.strictEqual(err, null); | 198 | 199 | callbacks._called[i] = chunk; | 199 | 200 | }]; | 200 | 201 | }).reduce(function(set, x) { | @@ -225,15 +226,19 @@ for (let i = 0; i < chunks.length; i++) { | 225 | 226 | { | 226 | 227 | // Verify end() callback | 227 | 228 | const tw = new TestWriter(); | 228 | | - tw.end(common.mustCall()); | | 229 | + tw.end(common.mustCall(function(err) { | | 230 | + assert.strictEqual(err, null); | | 231 | + })); | 229 | 232 | } | 230 | 233 |
| 231 | 234 | const helloWorldBuffer = Buffer.from('hello world'); | 232 | 235 |
| 233 | 236 | { | 234 | 237 | // Verify end() callback with chunk | 235 | 238 | const tw = new TestWriter(); | 236 | | - tw.end(helloWorldBuffer, common.mustCall()); | | 239 | + tw.end(helloWorldBuffer, common.mustCall(function(err) { | | 240 | + assert.strictEqual(err, null); | | 241 | + })); | 237 | 242 | } | 238 | 243 |
| 239 | 244 | { | |
|