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

assert: support custom errors by geek · Pull Request #15304 · nodejs/node · GitHub

/ node Public

assert: support custom errors - #15304

Closed
geek wants to merge 1 commit into
nodejs:masterfrom
geek:assert
Closed

assert: support custom errors#15304
geek wants to merge 1 commit into
nodejs:masterfrom
geek:assert

Conversation

geek commented Sep 10, 2017

Copy link
Copy Markdown
Member
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)

assert - support a way to provide a custom Error type for assertions. This will help make assert more useful for validating types and ranges.

geek requested a review from cjihrig September 10, 2017 01:47
nodejs-github-bot added the assert Issues and PRs related to the assert subsystem. label Sep 10, 2017

cjihrig left a comment

Copy link
Copy Markdown
Contributor

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 with a few suggestions. I think this is a useful change (helping with code coverage in modules using assert, and improving error types).

Comment thread doc/api/assert.md Outdated

Copy link
Copy Markdown
Contributor

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

f -> If

Comment thread test/parallel/test-assert.js Outdated

Copy link
Copy Markdown
Contributor

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

If you store the RangeError in a variable, you can just assert that e equals it.

Comment thread test/parallel/test-assert.js Outdated

Copy link
Copy Markdown
Contributor

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

For these tests involving try...catch, we don't know if the assertions were actually run. Can you add checks like these

Comment thread doc/api/assert.md Outdated

Copy link
Copy Markdown
Contributor

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

eq ual -> equal

cjihrig added the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 10, 2017

geek commented Sep 11, 2017

Copy link
Copy Markdown
Member Author

@cjihrig @vsemozhetbyt thanks for the feedback... updated!

BridgeAR 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

In general I like the idea a lot!
LGTM but I think it would be nice to use common.expectsError

threw = true;
assert.ok(e instanceof RangeError, 'Incorrect error type thrown');
}
assert.ok(threw);

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

It would actually be nice to use common.expectsError here. The test would be smaller in that case. You can check some other use cases as a reference.

Copy link
Copy Markdown
Member 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

Thank you for the suggestion. I tried expectsError, but for this simple case it didn't make the code any cleaner/shorter/simpler. I'm keeping it as is for now.

cjihrig commented Sep 12, 2017

Copy link
Copy Markdown
Contributor

cjihrig commented Sep 12, 2017

Copy link
Copy Markdown
Contributor

Landed in e13d1df. Thanks!

cjihrig closed this Sep 12, 2017
cjihrig pushed a commit that referenced this pull request Sep 12, 2017
This commit adds special handling of Error instances when passed
as the message argument to assert functions. With this commit,
if an Error is passed as the message, then that Error is thrown
instead of an AssertionError.

PR-URL: #15304
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
geek deleted the assert branch September 12, 2017 19:06

refack commented Sep 12, 2017

Copy link
Copy Markdown
Contributor

I like the concept of this PR, but I think it was rushed.

  1. semver-majors need two TSC approvals (this one has only @cjihrig's)
  2. expectsError conceptualy should be used to validate internal/errors since theoretically it should assert that an err.code exists.
  3. The assert module, although it has been unfrozen, should get some extra attention, since it's a fundamental language construct (and we might want to hoist it into spec).

(I'm not saying it should be reverted, but I do suggest we tweak it a bit before 9.0.0)

cjihrig commented Sep 12, 2017

Copy link
Copy Markdown
Contributor

@refack, definitely my bad on item 1. I apologize for that.

Regarding item 2, that is how the surrounding tests in that file are written, so I don't necessarily think that is wrong. Maybe that could be a good first contribution.

I don't really have any comment on item 3 other than the PR being open sufficiently long enough.

I do suggest we tweak it a bit before 9.0.0

Do you want to submit a follow up PR?

Again, my apologies for item 1.

refack commented Sep 12, 2017

Copy link
Copy Markdown
Contributor

I do suggest we tweak it a bit before 9.0.0
Do you want to submit a follow up PR?

I totally agree there's nothing bad in this PR (on the contrary, I see it's usufulness).
I'll try to either open a PR or a first-contribution issue.

addaleax pushed a commit to addaleax/node that referenced this pull request Sep 13, 2017
This commit adds special handling of Error instances when passed
as the message argument to assert functions. With this commit,
if an Error is passed as the message, then that Error is thrown
instead of an AssertionError.

PR-URL: nodejs#15304
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL