FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

assert: display better error message for assertion by SgtPooki · Pull Request #15883 · nodejs/node · GitHub

/ node Public

assert: display better error message for assertion - #15883

Closed
SgtPooki wants to merge 1 commit into
nodejs:masterfrom
SgtPooki:fixTestMsg
Closed

assert: display better error message for assertion#15883
SgtPooki wants to merge 1 commit into
nodejs:masterfrom
SgtPooki:fixTestMsg

Conversation

SgtPooki commented Oct 6, 2017

Copy link
Copy Markdown
Contributor

This commit makes understanding assertion failures easier by
displaying the values that failed the assertion.

Changes the error message from

➜ node git:(fixTestMsg) ✗ tools/test.py parallel/test-zlib-random-byte-pipes.js
=== release test-zlib-random-byte-pipes ===
Path: parallel/test-zlib-random-byte-pipes
assert.js:45
throw new errors.AssertionError({
^

AssertionError [ERR_ASSERTION]: hashes should match
at HashStream.out.on.common.mustCall (/Users/dempser/code/node/test/parallel/test-zlib-random-byte-pipes.js:154:10)
at HashStream. (/Users/dempser/code/node/test/common/index.js:517:15)
at emitOne (events.js:115:13)
at HashStream.emit (events.js:210:7)
at HashStream.end (/Users/dempser/code/node/test/parallel/test-zlib-random-byte-pipes.js:139:10)
at Gunzip.onend (_stream_readable.js:596:10)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:110:20)
at Gunzip.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1052:12)
Command: out/Release/node /Users/dempser/code/node/test/parallel/test-zlib-random-byte-pipes.js
[00:00|% 100|+ 0|- 1]: Done

to

➜ node git:(fixTestMsg) tools/test.py parallel/test-zlib-random-byte-pipes.js
=== release test-zlib-random-byte-pipes ===
Path: parallel/test-zlib-random-byte-pipes
assert.js:45
throw new errors.AssertionError({
^

AssertionError [ERR_ASSERTION]: Hash 'some non hash' equals '4663ea81710e8f7941232a9f46a99e11118f336d'.
at HashStream.out.on.common.mustCall (/Users/dempser/code/node/test/parallel/test-zlib-random-byte-pipes.js:154:10)
at HashStream. (/Users/dempser/code/node/test/common/index.js:517:15)
at emitOne (events.js:115:13)
at HashStream.emit (events.js:210:7)
at HashStream.end (/Users/dempser/code/node/test/parallel/test-zlib-random-byte-pipes.js:139:10)
at Gunzip.onend (_stream_readable.js:596:10)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:110:20)
at Gunzip.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1052:12)
Command: out/Release/node /Users/dempser/code/node/test/parallel/test-zlib-random-byte-pipes.js
[00:00|% 100|+ 0|- 1]: Done

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

This commit makes understanding assertion failures easier by
displaying the values that failed the assertion.
nodejs-github-bot added the test Issues and PRs related to the tests. label Oct 6, 2017
mscdex added the zlib Issues and PRs related to the zlib subsystem. label Oct 6, 2017
Trott added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Oct 6, 2017

Trott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. It might be even better to remove the message entirely and use the default message from assert.strictEqual().

Trott commented Oct 8, 2017

Copy link
Copy Markdown
Member

Trott self-assigned this Oct 9, 2017
Trott pushed a commit to Trott/io.js that referenced this pull request Oct 9, 2017
This commit makes understanding assertion failures easier by
displaying the values that failed the assertion.

PR-URL: nodejs#15883
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>

Trott commented Oct 9, 2017

Copy link
Copy Markdown
Member

Landed in beb2357.
Thanks for the contribution! 🎉

Trott closed this Oct 9, 2017

out.on('data', common.mustCall((c) => {
assert.strictEqual(c, inp._hash, 'hashes should match');
assert.strictEqual(c, inp._hash, `Hash '${c}' equals '${inp._hash}'.`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is actually not quite correct (although it was equally wrong before 😁 ). The message is displayed if the assert fails, which only happens when the two values are not equal to each other.

@SgtPooki if you could push a commit that just removes the message altogether (making it assert.strictEqual(c, inp._hash); that would be really helpful.

Copy link
Copy Markdown
Contributor Author

I can, but assertion errors are typically worded similarly to commit messages: active present voice. The error message says "assertion error: msg" the error is that hashes should equal.

The default message shows "assertion error: Val1 === val2" which is the same thing but without context.

I decided to go with the custom message because I thought that mentioning they should be hashes was more helpful than the default.

MylesBorins pushed a commit that referenced this pull request Oct 11, 2017
This commit makes understanding assertion failures easier by
displaying the values that failed the assertion.

PR-URL: #15883
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
MylesBorins mentioned this pull request Oct 11, 2017
addaleax pushed a commit to addaleax/ayo that referenced this pull request Oct 12, 2017
This commit makes understanding assertion failures easier by
displaying the values that failed the assertion.

PR-URL: nodejs/node#15883
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
MylesBorins pushed a commit that referenced this pull request Oct 17, 2017
This commit makes understanding assertion failures easier by
displaying the values that failed the assertion.

PR-URL: #15883
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
MylesBorins mentioned this pull request Oct 17, 2017
MylesBorins pushed a commit that referenced this pull request Oct 18, 2017
This commit makes understanding assertion failures easier by
displaying the values that failed the assertion.

PR-URL: #15883
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
MylesBorins pushed a commit that referenced this pull request Oct 25, 2017
This commit makes understanding assertion failures easier by
displaying the values that failed the assertion.

PR-URL: #15883
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
MylesBorins mentioned this pull request Nov 3, 2017
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

Labels

code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. test Issues and PRs related to the tests. zlib Issues and PRs related to the zlib subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL