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

assert: wrap original err on `ifError` fail by refack · Pull Request #12820 · nodejs/node · GitHub

/ node Public

assert: wrap original err on ifError fail - #12820

Closed
refack wants to merge 1 commit into
nodejs:masterfrom
refack:assrt-iferror
Closed

assert: wrap original err on ifError fail#12820
refack wants to merge 1 commit into
nodejs:masterfrom
refack:assrt-iferror

Conversation

refack commented May 4, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

For assert.ifError fails, wrap the original err in a new AssertionError

Inspiration: #12803 (comment)
/cc @nodejs/testing

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

test, assert

refack added assert Issues and PRs related to the assert subsystem. test Issues and PRs related to the tests. labels May 4, 2017
nodejs-github-bot added the assert Issues and PRs related to the assert subsystem. label May 4, 2017

refack commented May 4, 2017
edited
Loading

Copy link
Copy Markdown
Contributor Author

The message will not change, but the stack trace will 🤔

refack requested a review from addaleax May 4, 2017 03:15

Trott commented May 4, 2017

Copy link
Copy Markdown
Member

It might be the smallest semver-major ever, but I would still say semver-major.

Imagine the impact on someone reading the stack traces if they run the same test on different versions of Node.js (which is what someone might do if they suspect they are triggering a bug in Node.js itself). If assert.ifError() returns a different stack trace in the same exact situation between Node.js 7.10.0 and Node.js 8.0.0, well, that's what happens between major versions. But different results between Node.js 7.10.0 and 7.11.0? I'd be less understanding about that...

addaleax commented May 4, 2017

Copy link
Copy Markdown
Member

Is this a good idea, though? I think I would usually be more interested in the original stack trace (and apart from that, I think that this won’t work if somebody accessed err.stack before ifError() is called) to figure out why there was an error

joyeecheung 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

We should add a test for this..

jasnell commented May 4, 2017

Copy link
Copy Markdown
Member

I'm not sure this is a good change to make. The errors are created elsewhere and passed here. Changing the stack trace would definitely be a breaking change (even if a mild one). I don't think this is behavior anyone would expect.

refack commented May 4, 2017

Copy link
Copy Markdown
Contributor Author

Is this a good idea, though? I think I would usually be more interested in the original stack trace (and apart from that, I think that this won’t work if somebody accessed err.stack before ifError() is called) to figure out why there was an error

One could argue that if you want the original stack, just throw it. If you use assert, you want to knwo which asset failed...
It came to me after I sew this:

c:\code\node$ node --no-deprecation test/parallel/test-fs-chmod.js
33060
assert.js:378
assert.ifError = function ifError(err) { if (err) throw err; };
                                                  ^

Error: EPERM: operation not permitted, open 'd:\code\node\test\fixtures\a1.js'

cjihrig commented May 4, 2017

Copy link
Copy Markdown
Contributor

I think we should either throw the existing error, as is, or throw a new assertion error. This hybrid seems confusing.

refack commented May 4, 2017

Copy link
Copy Markdown
Contributor Author

I think we should either throw the existing error, as is, or throw a new assertion error. This hybrid seems confusing.

Bingo!

refack added the semver-major PRs that contain breaking changes and should be released in the next major version. label May 4, 2017

refack commented May 4, 2017

Copy link
Copy Markdown
Contributor Author

Changed to wrapping the original err in a new AssertionError (per @cjihrig's comment).
Now It's definitely semver-major

refack changed the title assert: generate interesting stack trace assert: wrap original err on ifError fail May 4, 2017

jasnell commented May 4, 2017

Copy link
Copy Markdown
Member

Wrapping in the AssertionError works. We will definitely want to run some CITGM tests on this tho

refack commented May 4, 2017

Copy link
Copy Markdown
Contributor Author

refack commented May 26, 2017

Copy link
Copy Markdown
Contributor Author

refack self-assigned this May 26, 2017
Comment thread lib/assert.js Outdated

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

message isn't used.

Copy link
Copy Markdown
Contributor Author

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

Ack.
Forgot to carry it over into the last commit.

refack commented May 27, 2017

Copy link
Copy Markdown
Contributor Author

refack commented May 27, 2017
edited
Loading

Copy link
Copy Markdown
Contributor Author

refack commented Jun 2, 2017

Copy link
Copy Markdown
Contributor Author

Ping @nodejs/testing

refack commented Jun 9, 2017

Copy link
Copy Markdown
Contributor Author

I now kinda hate the current ifError. Re:

1307	parallel/test-util-callbackify	
duration_ms	0.89
severity	fail
stack	->

assert.js:586
assert.ifError = function ifError(err) { if (err) throw err; };
                                                  ^
function () {
    context.actual++;
    return fn.apply(this, arguments);
  }

Comment thread doc/api/assert.md

Throws an `AssertionError` if `value` is truthy. This is useful when testing the
`error` argument in callbacks. If the `message` parameter is undefined, a
default error message is assigned, and `value` is be appended to it.

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

I feel this is somewhat contradicting each other. If it should be used in callbacks, there should always either be an error or the result but never both at the same time.

common.expectsError({
code: 'ERR_ASSERTION',
type: a.AssertionError,
message: /^Error: test_error_slug$/m

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

I am not sure how this is any different from the test above. I actually would expect this test to fail because I would have expected it to be wrapped in the ifError failed part.

Comment thread lib/assert.js
assert.ifError = function ifError(err) { if (err) throw err; };
assert.ifError = function ifError(err, message) {
if (!err) return;
message = message || `ifError failed. Original error:\n${err}`;

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

Hm, is ifError really failing here? Maybe smth. like ifError encountered unexpected error: ... might be more intuitive?

Copy link
Copy Markdown
Member

Ping @refack

BridgeAR commented Oct 2, 2017

Copy link
Copy Markdown
Member

I am closing this due to the long inactivity. @refack please reopen if you would like to pursue this further.

BridgeAR closed this Oct 2, 2017
refack removed their assignment Oct 12, 2018
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

assert Issues and PRs related to the assert subsystem. semver-major PRs that contain breaking changes and should be released in the next major version. test Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants


Back | FazBrowse Home | New Git URL