{{ message }}
errors: remove needless lazyAssert #11891
Closed
DavidCai1111 wants to merge 1 commit into
Closed
Conversation
cjihrig
approved these changes
Mar 17, 2017
Member
jasnell
approved these changes
Mar 17, 2017
watilde
approved these changes
Mar 17, 2017
Member
Member
|
Landed in a00c9e95 |
Member
|
If I'm not mistaken, with this change, we can't convert If I make this change: diff --git a/lib/assert.js b/lib/assert.js
index df575c0..9315783 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -25,6 +25,7 @@ const compare = process.binding('buffer').compare;
const util = require('util');
const objectToString = require('internal/util').objectToString;
const Buffer = require('buffer').Buffer;
+const errors = require('internal/errors');
// The assert module provides functions that throw
// AssertionError's when particular conditions are not met. The
@@ -391,7 +392,7 @@ function _throws(shouldThrow, block, expected, message) {
var actual;
if (typeof block !== 'function') {
- throw new TypeError('"block" argument must be a function');
+ throw new errors.TypeError('ERR_ARG_FUNCTION');
}
if (typeof expected === 'string') {
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 01e4e48..15198b4 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -80,4 +80,5 @@ module.exports = exports = {
//
// Note: Please try to keep these in alphabetical order
E('ERR_ASSERTION', (msg) => msg);
+E('ERR_ARG_FUNCTION', '"block" argument must be a function');
// Add new errors from here......and then compile, trying to run $ ./node
internal/errors.js:57
assert(messages.has(sym) === false, `Error symbol: ${sym} was already used.`);
^
TypeError: assert is not a function
at E (internal/errors.js:57:3)
at internal/errors.js:82:1
at NativeModule.compile (bootstrap_node.js:545:7)
at NativeModule.require (bootstrap_node.js:486:18)
at assert.js:28:16
at NativeModule.compile (bootstrap_node.js:545:7)
at NativeModule.require (bootstrap_node.js:486:18)
at timers.js:26:16
at NativeModule.compile (bootstrap_node.js:545:7)
at Function.NativeModule.require (bootstrap_node.js:486:18)
$ |
Member
|
I guess we can convert the |
Member
Author
|
@Trott Oh, sorry for not taking the scene that using diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 01e4e482cb..363db9728b 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -6,7 +6,6 @@
// value statically and permanently identifies the error. While the error
// message may change, the code should not.
-const assert = require('assert');
const kCode = Symbol('code');
const messages = new Map();
@@ -36,10 +35,15 @@ function makeNodeError(Base) {
}
function message(key, args) {
- assert.strictEqual(typeof key, 'string');
+ if (typeof key !== 'string')
+ throw new TypeError('"key" argument must be a string');
+
const util = lazyUtil();
const msg = messages.get(key);
- assert(msg, `An invalid error message key was used: ${key}.`);
+
+ if (!msg)
+ throw new Error(`An invalid error message key was used: ${key}.`);
+
let fmt = util.format;
if (typeof msg === 'function') {
fmt = msg;
@@ -54,7 +58,9 @@ function message(key, args) {
// Utility function for registering the error codes. Only used here. Exported
// *only* to allow for testing.
function E(sym, val) {
- assert(messages.has(sym) === false, `Error symbol: ${sym} was already used.`);
+ if (messages.has(sym))
+ throw new Error(`Error symbol: ${sym} was already used.`);
+
messages.set(sym, typeof val === 'function' ? val : String(val));
} |
Member
|
@DavidCai1993 Seems good to me if everyone else is 👍 about it. |
Member
Author
MylesBorins
pushed a commit
that referenced
this pull request
Mar 28, 2017
PR-URL: #11891 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Since now the
lazyAssert()function will be called inE()andE()will be called suddenly at the end of the script, so there is no need to require theassertmodule lazily any more.Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
errors