-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
[WIP] errors: add internal/errors module #6573
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,25 @@ var StringDecoder; | |
|
||
util.inherits(Readable, Stream); | ||
|
||
// This does not use the internal/errors so that it can remain | ||
// portable with the readable-streams module. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably also point to these from the main functions in case someone tries to edit them without knowing these exist? |
||
function typeError(code, args) { | ||
const assert = require('assert'); | ||
var msg; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use |
||
switch (code) { | ||
case 'EINVALIDCHUNK': | ||
msg = 'Invalid non-string/buffer chunk'; | ||
break; | ||
default: | ||
assert.fail(null, null, 'Unknown error code.'); | ||
} | ||
var error = new TypeError(msg); | ||
Error.captureStackTrace(error, typeError); | ||
error.code = error.errno = code; | ||
error.name = 'TypeError[' + code + ']'; | ||
return error; | ||
} | ||
|
||
const hasPrependListener = typeof EE.prototype.prependListener === 'function'; | ||
|
||
function prependListener(emitter, event, fn) { | ||
|
@@ -396,7 +415,7 @@ function chunkInvalid(state, chunk) { | |
chunk !== null && | ||
chunk !== undefined && | ||
!state.objectMode) { | ||
er = new TypeError('Invalid non-string/buffer chunk'); | ||
er = new typeError('EINVALIDCHUNK'); | ||
} | ||
return er; | ||
} | ||
|
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.
shouldn't
require
s be at the top of the file?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.
When there are only one or two cases in a file, I did it like this so the
require is only called in error conditions
On May 9, 2016 5:27 PM, "Rod Vagg" [email protected] wrote:
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.
Lazy loading is pretty common in core code. Though I'm not sure how much it actually saves us now.