-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
errors,http_server: migrate to use internal/errors.js #13301
Conversation
lib/_http_server.js
Outdated
@@ -211,8 +212,8 @@ function writeHead(statusCode, reason, obj) { | |||
} | |||
if (k === undefined) { | |||
if (this._header) { | |||
throw new Error('Can\'t render headers after they are sent to the ' + | |||
'client'); | |||
throw new errors.Error('ERR_ASSERTION', 'Can\'t render headers ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're updating anyway, it would be nice to get rid of the contraction.
Cannot render headers ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERR_ASSERTION
is the wrong choice here. That should be reserved for uses of the assert
module. A new error code would be more appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasnell Rectifications done. Thank You
lib/_http_server.js
Outdated
@@ -223,7 +224,8 @@ function writeHead(statusCode, reason, obj) { | |||
} | |||
|
|||
if (common._checkInvalidHeaderChar(this.statusMessage)) | |||
throw new Error('Invalid character in statusMessage.'); | |||
throw new errors.Error('ERR_ASSERTION', 'Invalid character in ' + | |||
'statusMessage.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, ERR_ASSERTION
is the wrong choice here. A new error code would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
lib/internal/errors.js
Outdated
@@ -117,13 +117,16 @@ E('ERR_CONSOLE_WRITABLE_STREAM', | |||
E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range'); | |||
E('ERR_INVALID_ARG_TYPE', invalidArgType); | |||
E('ERR_INVALID_CALLBACK', 'callback must be a function'); | |||
E('ERR_INVALID_CHAR', 'Invalid character in statusMessage.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is specific to http, perhaps ERR_HTTP_INVALID_CHAR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-phrased.
lib/internal/errors.js
Outdated
E('ERR_INVALID_FILE_URL_HOST', 'File URL host %s'); | ||
E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s'); | ||
E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent'); | ||
E('ERR_INVALID_OPT_VALUE', | ||
(name, value) => { | ||
return `The value "${String(value)}" is invalid for option "${name}"`; | ||
}); | ||
E('ERR_INVALID_STATUS_CODE', | ||
(originalStatusCode) => `Invalid status code: ${originalStatusCode}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here... ERR_HTTP_INVALID_STATUS_CODE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
lib/internal/errors.js
Outdated
@@ -139,6 +142,8 @@ E('ERR_IPC_DISCONNECTED', 'IPC channel is already disconnected'); | |||
E('ERR_IPC_ONE_PIPE', 'Child process can have only one IPC pipe'); | |||
E('ERR_IPC_SYNC_FORK', 'IPC cannot be used with synchronous forks'); | |||
E('ERR_MISSING_ARGS', missingArgs); | |||
E('ERR_RENDER_HEADER', | |||
'Cannot render headers after they are sent to the client'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERR_HTTP_HEADERS_SENT
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rectified. Thanks!
@@ -1,3 +1,5 @@ | |||
// Flags: --expose-internals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't need the --expose-internals
flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
@@ -19,6 +19,8 @@ | |||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | |||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
|
|||
// Flag: --expose-internals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, this shouldn't need the --expose-internals
flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a nit
lib/_http_server.js
Outdated
@@ -223,7 +225,8 @@ function writeHead(statusCode, reason, obj) { | |||
} | |||
|
|||
if (common._checkInvalidHeaderChar(this.statusMessage)) | |||
throw new Error('Invalid character in statusMessage.'); | |||
throw new errors.Error('ERR_HTTP_INVALID_CHAR', 'Invalid character in ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing its broken into 2 strings to avoid the long line. I'm not sure I've seen us use the + for this, instead could you just put the 'Invalid ...' on a second line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done as per suggestion. Thanks!
PR-URL: #13301 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
Landed in a9f798e |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
_http_server.js
internal/errors.js
ref: #11273
I read and understood the contribution guidelines, please review and suggest.
@jasnell
Thanks.