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: restore TypeError if no arguments #12843

Closed
wants to merge 1 commit into from

Conversation

Trott
Copy link
Member

@Trott Trott commented May 5, 2017

In Node 7.x, calling throw new assert.AssertionError() resulted in a
TypeError.

In current master, the same call does not result in an error but, due to
the default option, it results in uninformative output ("undefined
undefined undefined").

This change removes the default argument, restoring a TypeError if there
is no argument. This also will restore our test coverage to 100%. (The
default argument is not tested in our current test suite.)

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

assert

@Trott Trott added the assert Issues and PRs related to the assert subsystem. label May 5, 2017
@jasnell
Copy link
Member

jasnell commented May 5, 2017

I think I'd rather keep the default and fix the message so that it's more helpful in the default case

@Trott
Copy link
Member Author

Trott commented May 5, 2017

I think I'd rather keep the default and fix the message so that it's more helpful in the default case

There is no such thing as a "default case" for an assertion. By definition, an assertion needs to be about something specific. A default argument here isn't fulfilling some unmet need. It's just extra surface area we don't need. Although this does make me realize I should add a test...

@jasnell
Copy link
Member

jasnell commented May 5, 2017

Ok. I'm not going to object to the change over a simple personal preference ;-) ... the code LGTM

In Node 7.x, calling `throw new assert.AssertionError()` resulted in a
TypeError.

In current master, the same call does not result in an error but, due to
the default option, it results in uninformative output ("undefined
undefined undefined").

This change removes the default argument, restoring a TypeError if there
is no argument. This also will restore our test coverage to 100%. (The
default argument is not tested in our current test suite.)
@Trott
Copy link
Member Author

Trott commented May 6, 2017

});
{
// bad args to AssertionError constructor should throw TypeError
const args = [1, true, false, '', null, Infinity, Symbol('test'), undefined];
Copy link
Contributor

@refack refack May 6, 2017

Choose a reason for hiding this comment

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

If you've went to the trouble of making it more readable, why not call it badArgs or invalidArgs. I've seen the line is 77 chars long, but maybe... Maybe just invalids or bad?

Copy link
Contributor

Choose a reason for hiding this comment

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

nonArgs

Trott added a commit to Trott/io.js that referenced this pull request May 8, 2017
In Node 7.x, calling `throw new assert.AssertionError()` resulted in a
TypeError.

In current master, the same call does not result in an error but, due to
the default option, it results in uninformative output ("undefined
undefined undefined").

This change removes the default argument, restoring a TypeError if there
is no argument. This also will restore our test coverage to 100%. (The
default argument is not tested in our current test suite.)

PR-URL: nodejs#12843
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@Trott
Copy link
Member Author

Trott commented May 8, 2017

Landed in f6247a9

@Trott Trott closed this May 8, 2017
anchnk pushed a commit to anchnk/node that referenced this pull request May 19, 2017
In Node 7.x, calling `throw new assert.AssertionError()` resulted in a
TypeError.

In current master, the same call does not result in an error but, due to
the default option, it results in uninformative output ("undefined
undefined undefined").

This change removes the default argument, restoring a TypeError if there
is no argument. This also will restore our test coverage to 100%. (The
default argument is not tested in our current test suite.)

PR-URL: nodejs#12843
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@jasnell jasnell mentioned this pull request May 11, 2017
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
@gibfahn
Copy link
Member

gibfahn commented Jun 20, 2017

In Node 7.x, calling throw new assert.AssertionError() resulted in a
TypeError.

In current master, the same call does not result in an error but, due to
the default option, it results in uninformative output ("undefined
undefined undefined").

I think this means that this isn't needed on v6.x, correct me if I'm wrong @Trott

@Trott
Copy link
Member Author

Trott commented Jun 21, 2017

I think this means that this isn't needed on v6.x, correct me if I'm wrong @Trott

I think that's right.

@Trott Trott deleted the full-assert-coverage branch January 13, 2022 22:45
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants