-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: add internal/errors.js #9265
Conversation
lib/internal/errors.js
Outdated
const kCode = Symbol('code'); | ||
|
||
class NodeError extends Error { | ||
constructor(key, ...args) { |
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.
Can we replace all of the rest args usage with a copy loop or whatever is fastest currently?
lib/internal/url.js
Outdated
if (flags & binding.URL_FLAGS_FAILED) | ||
throw new TypeError('Invalid URL'); | ||
if (flags & binding.URL_FLAGS_FAILED) { | ||
const errors = require('internal/errors'); |
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.
Can't this be placed at the top of the file?
lib/internal/util.js
Outdated
if (noCrypto) | ||
throw new Error('Node.js is not compiled with openssl crypto support'); | ||
if (noCrypto) { | ||
const errors = require('internal/errors'); |
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.
Ditto?
Add the internal/errors.js core mechanism.
Update most of the errors to use internal/errors. Purposefully leaves two errors in place to be updated later.
@mscdex ... updated! |
Can. Kept it local to the error since it's the only instance of use. On Monday, October 24, 2016, Brian White [email protected] wrote:
|
|
||
// Utility function for registering the error codes. | ||
function E(sym, val) { | ||
exports[Symbol.for(String(sym).toUpperCase())] = |
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 using the global symbol registry, perhaps we should add a NODE_
prefix to the key.
// to the readable-stream standalone module. If the logic here changes at all, | ||
// then those also need to be checked. | ||
|
||
const kCode = Symbol('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.
Symbol('error code')
?
const kCode = Symbol('code'); | ||
|
||
class NodeError extends Error { | ||
constructor(key /**, ...args **/) { |
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 think the overhead of rest parameters is negligible here.
Testcase: https://jsperf.com/custom-error-with-rest-params
@@ -415,7 +415,8 @@ | |||
} | |||
|
|||
if (!NativeModule.exists(id)) { | |||
throw new Error(`No such native module ${id}`); | |||
const errors = require('internal/errors'); |
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.
nit: const {Error} = require('internal/errors');
Checklist
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
errors
Description of change
A more incremental version of #6573.
Introduces the internal/errors.js module and begins updating errors in the
internal modules to use it. This is intentionally incomplete. Other errors can
be migrated over to this incrementally.
This is semver-major because several of the error messages are updated
in the process.