Skip to content
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

Closed

Conversation

DavidCai1111
Copy link
Member

Add duplicate error symbol checking in E() to avoid potential confusing result.

Improve coverage of internal/errors.js.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

errors

@nodejs-github-bot nodejs-github-bot added the errors Issues and PRs related to JavaScript errors originated in Node.js core. label Mar 13, 2017
@@ -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'),
Copy link
Contributor

@mscdex mscdex Mar 13, 2017

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\.$/);

@mscdex
Copy link
Contributor

mscdex commented Mar 13, 2017

The first line of the commit message exceeds 50 characters.

@DavidCai1111 DavidCai1111 force-pushed the errors/check-used-sym branch 3 times, most recently from 14348ce to 1e4ab50 Compare March 13, 2017 15:55
@DavidCai1111
Copy link
Member Author

@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.$/
Copy link
Contributor

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.

Copy link
Member Author

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.

@DavidCai1111 DavidCai1111 changed the title errors: add duplicate symbol checking in E() and improve coverage errors: add duplicate symbol checking in E() and increase coverage Mar 13, 2017
@@ -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.`);
Copy link
Member

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" ?

Copy link
Member Author

@DavidCai1111 DavidCai1111 Mar 13, 2017

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.
@mscdex
Copy link
Contributor

mscdex commented Mar 13, 2017

@fhinkel
Copy link
Member

fhinkel commented Mar 15, 2017

Thanks. Landed in b5eccc4

@fhinkel fhinkel closed this Mar 15, 2017
fhinkel pushed a commit that referenced this pull request Mar 15, 2017
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]>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Mar 20, 2017
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]>
jungx098 pushed a commit to jungx098/node that referenced this pull request Mar 21, 2017
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]>
@MylesBorins
Copy link
Contributor

Doesn't land on v6.x afaict. If it does land somewhere else in the tree lmk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants