lib: migrate _http_outgoing.js's remaining errors

A couple of lib/_http_outgoing.js's errors were still in the
"old style": `throw new Error(<some message here>)`.

This commit migrates those 2 old style errors to the "new style":
internal/errors.js's error-system.

In the future, changes to these errors' messages won't break
semver-major status. With the old style, changes to these errors'
messages broke semver-major status. It was inconvenient.

Refs: https://github.com/nodejs/node/issues/17709
PR-URL: https://github.com/nodejs/node/pull/17837
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anton Paras 2017-12-23 01:53:17 -08:00 коммит произвёл Joyee Cheung
Родитель 9f122e3b55
Коммит d3ac18a176
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: F586868AAD831D0C
5 изменённых файлов: 18 добавлений и 16 удалений

Просмотреть файл

@ -629,7 +629,7 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) {
function write_(msg, chunk, encoding, callback, fromEnd) { function write_(msg, chunk, encoding, callback, fromEnd) {
if (msg.finished) { if (msg.finished) {
var err = new Error('write after end'); const err = new errors.Error('ERR_STREAM_WRITE_AFTER_END');
nextTick(msg.socket && msg.socket[async_id_symbol], nextTick(msg.socket && msg.socket[async_id_symbol],
writeAfterEndNT.bind(msg), writeAfterEndNT.bind(msg),
err, err,
@ -880,7 +880,7 @@ OutgoingMessage.prototype.flush = internalUtil.deprecate(function() {
OutgoingMessage.prototype.pipe = function pipe() { OutgoingMessage.prototype.pipe = function pipe() {
// OutgoingMessage should be write-only. Piping from it is disabled. // OutgoingMessage should be write-only. Piping from it is disabled.
this.emit('error', new Error('Cannot pipe, not readable')); this.emit('error', new errors.Error('ERR_STREAM_CANNOT_PIPE'));
}; };
module.exports = { module.exports = {

Просмотреть файл

@ -25,8 +25,9 @@ const assert = require('assert');
const http = require('http'); const http = require('http');
const server = http.Server(common.mustCall(function(req, res) { const server = http.Server(common.mustCall(function(req, res) {
res.on('error', common.mustCall(function onResError(err) { res.on('error', common.expectsError({
assert.strictEqual(err.message, 'write after end'); code: 'ERR_STREAM_WRITE_AFTER_END',
type: Error
})); }));
res.write('This should write.'); res.write('This should write.');

Просмотреть файл

@ -2,7 +2,6 @@
const common = require('../common'); const common = require('../common');
const http = require('http'); const http = require('http');
const assert = require('assert');
// Fix for https://github.com/nodejs/node/issues/14368 // Fix for https://github.com/nodejs/node/issues/14368
@ -10,7 +9,10 @@ const server = http.createServer(handle);
function handle(req, res) { function handle(req, res) {
res.on('error', common.mustCall((err) => { res.on('error', common.mustCall((err) => {
assert.strictEqual(err.message, 'write after end'); common.expectsError({
code: 'ERR_STREAM_WRITE_AFTER_END',
type: Error
})(err);
server.close(); server.close();
})); }));

Просмотреть файл

@ -1,15 +1,14 @@
'use strict'; 'use strict';
const assert = require('assert');
const common = require('../common'); const common = require('../common');
const OutgoingMessage = require('_http_outgoing').OutgoingMessage; const OutgoingMessage = require('_http_outgoing').OutgoingMessage;
// Verify that an error is thrown upon a call to `OutgoingMessage.pipe`. // Verify that an error is thrown upon a call to `OutgoingMessage.pipe`.
const outgoingMessage = new OutgoingMessage(); const outgoingMessage = new OutgoingMessage();
assert.throws( common.expectsError(
common.mustCall(() => { outgoingMessage.pipe(outgoingMessage); }), () => { outgoingMessage.pipe(outgoingMessage); },
(err) => { {
return ((err instanceof Error) && /Cannot pipe, not readable/.test(err)); code: 'ERR_STREAM_CANNOT_PIPE',
}, type: Error
'OutgoingMessage.pipe should throw an error' }
); );

Просмотреть файл

@ -1,7 +1,6 @@
'use strict'; 'use strict';
const common = require('../common'); const common = require('../common');
const http = require('http'); const http = require('http');
const assert = require('assert');
const stream = require('stream'); const stream = require('stream');
// Verify that when piping a stream to an `OutgoingMessage` (or a type that // Verify that when piping a stream to an `OutgoingMessage` (or a type that
@ -17,8 +16,9 @@ const server = http.createServer(common.mustCall(function(req, res) {
process.nextTick(common.mustCall(() => { process.nextTick(common.mustCall(() => {
res.end(); res.end();
myStream.emit('data', 'some data'); myStream.emit('data', 'some data');
res.on('error', common.mustCall(function(err) { res.on('error', common.expectsError({
assert.strictEqual(err.message, 'write after end'); code: 'ERR_STREAM_WRITE_AFTER_END',
type: Error
})); }));
process.nextTick(common.mustCall(() => server.close())); process.nextTick(common.mustCall(() => server.close()));