-
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
errors: add duplicate symbol checking in E() and increase coverage #11829
Conversation
@@ -118,3 +124,8 @@ assert.throws(() => { | |||
type: TypeError, | |||
message: /^Error for testing 2/ })); | |||
}, /AssertionError: .+ does not match \S/); | |||
|
|||
assert.doesNotThrow(() => errors.E('TEST_ERROR_USED_SYMBOL')); | |||
assert.throws(() => errors.E('TEST_ERROR_USED_SYMBOL'), |
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.
FWIW you could move the arguments to new (indented) lines to avoid new RegExp()
and string concatenation:
assert.throws(
() => errors.E('TEST_ERROR_USED_SYMBOL'),
/^AssertionError: Error symbol: TEST_ERROR_USED_SYMBOL was used\.$/);
The first line of the commit message exceeds 50 characters. |
14348ce
to
1e4ab50
Compare
@mscdex Thanks for reviewing. Updated, PTAL. |
assert.doesNotThrow(() => errors.E('TEST_ERROR_USED_SYMBOL')); | ||
assert.throws( | ||
() => errors.E('TEST_ERROR_USED_SYMBOL'), | ||
/^AssertionError: Error symbol: TEST_ERROR_USED_SYMBOL was used.$/ |
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.
The period should be escaped to avoid matching any character instead of a literal period.
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.
Oh...Sorry for forgetting that. Updated.
1e4ab50
to
ffbd3a3
Compare
lib/internal/errors.js
Outdated
@@ -60,6 +60,8 @@ function message(key, args) { | |||
// Utility function for registering the error codes. Only used here. Exported | |||
// *only* to allow for testing. | |||
function E(sym, val) { | |||
const assert = lazyAssert(); | |||
assert(messages.has(sym) === false, `Error symbol: ${sym} was used.`); |
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.
maybe "was used before" or "was already used" ?
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.
@targos Thanks for reviewing. Changed to "was already used"
, PTAL.
Add duplicate symbol checking in E() to avoid potential confusing result. Increase coverage of internal/errors.
ffbd3a3
to
a907059
Compare
Thanks. Landed in b5eccc4 |
Add duplicate symbol checking in E() to avoid potential confusing result. Increase coverage of internal/errors. PR-URL: #11829 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Add duplicate symbol checking in E() to avoid potential confusing result. Increase coverage of internal/errors. PR-URL: nodejs#11829 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Add duplicate symbol checking in E() to avoid potential confusing result. Increase coverage of internal/errors. PR-URL: nodejs#11829 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Doesn't land on v6.x afaict. If it does land somewhere else in the tree lmk |
Add duplicate error symbol checking in
E()
to avoid potential confusing result.Improve coverage of
internal/errors.js
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
errors