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

assert: display better error message for assertion #15883

Closed
wants to merge 1 commit into from

Conversation

SgtPooki
Copy link
Contributor

@SgtPooki SgtPooki commented Oct 6, 2017

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 nodejs-github-bot added the test Issues and PRs related to the tests. label Oct 6, 2017
@mscdex mscdex added the zlib Issues and PRs related to the zlib subsystem. label Oct 6, 2017
@Trott Trott added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Oct 6, 2017
Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

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

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

@Trott
Copy link
Member

Trott commented Oct 8, 2017

@Trott 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 <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
@Trott
Copy link
Member

Trott commented Oct 9, 2017

Landed in beb2357.
Thanks for the contribution! 🎉

@Trott Trott closed this Oct 9, 2017
@@ -150,5 +150,5 @@ const gunz = zlib.createGunzip();
inp.pipe(gzip).pipe(gunz).pipe(out);

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
Member

Choose a reason for hiding this comment

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

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.

@SgtPooki
Copy link
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 <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
@MylesBorins 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 <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
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 <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
@MylesBorins 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 <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
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 <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Nov 3, 2017
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