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

errors: multiple updates #15002

Closed
wants to merge 2 commits into from
Closed

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Aug 24, 2017

An alternative to #14350 ... eliminates the circular dependency with the assert module.

Also, export the defined error keys as constants. Some have said this makes it easier but I'm not fully convinced.

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

errors

@nodejs-github-bot nodejs-github-bot added the errors Issues and PRs related to JavaScript errors originated in Node.js core. label Aug 24, 2017
message,
actual: false,
expected: true,
operator: '=='
Copy link
Member

Choose a reason for hiding this comment

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

This should be ===.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, since this is loose equality, shouldn't it stay as ==? The current assert() function uses == as well (https://github.com/nodejs/node/blob/master/lib/assert.js#L78)

Copy link
Member

@lpinca lpinca Aug 24, 2017

Choose a reason for hiding this comment

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

@evanlucas if I'm not wrong there only assert.strictEqual() is currently used in this file.

Edit: nvm didn't see https://github.com/nodejs/node/pull/15002/files#diff-5a3344c263a73c663dd1cfcb91880fd7R70. Yes it's better to keep ==, ignore my comment.

Copy link
Contributor

@refack refack Aug 29, 2017

Choose a reason for hiding this comment

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

IMHO since this is an internal module assertions should be made in /test/, so there's no need for runtime assertions at all.

@jasnell
Copy link
Member Author

jasnell commented Aug 29, 2017

@nodejs/collaborators ... ping!

Copy link
Member

@lpinca lpinca left a comment

Choose a reason for hiding this comment

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

LGTM. I'm only a bit hesitant about exporting the constants.

@jasnell
Copy link
Member Author

jasnell commented Aug 29, 2017

As am I, to be honest, I'm not convinced that it will be all that useful.

Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

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

Not too worried about exporting the constants.

Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

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

IMHO assert should be removed for this module

message,
actual: false,
expected: true,
operator: '=='
Copy link
Contributor

@refack refack Aug 29, 2017

Choose a reason for hiding this comment

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

IMHO since this is an internal module assertions should be made in /test/, so there's no need for runtime assertions at all.

@jasnell
Copy link
Member Author

jasnell commented Aug 29, 2017

@refack... that's certainly a valid argument also :-)

@BridgeAR
Copy link
Member

I agree with @refack that using AssertionErrors here is not required and I would actually like to get rid of all asserts in /lib.

I am also not convinced about the export of the constants.

@jasnell
Copy link
Member Author

jasnell commented Aug 31, 2017

Looking at it further, I don't think we should remove the asserts. In particular, if someone ends up passing something like new errors.Error(), the result is a really odd code. Just as we have CHECKs at the C/C++ layer, we should have some basic checks at the js layer to keep from footgunning ourselves.

I will drop the commit that exports the constants tho.

@refack ... let's look at the possibility of pulling the asserts separately.

@BridgeAR
Copy link
Member

Well, I did not mean to get rid of the checks but I think it is good enough if we use if (truthy) { fail }. But probably it is fine to just stick to the asserts as they are.

Another note - as I pointed out in #14350, this is not really a alternative to it as it tries to solve something different.

@refack
Copy link
Contributor

refack commented Aug 31, 2017

Looking at it further, I don't think we should remove the asserts. In particular, if someone ends up passing something like new errors.Error(), the result is a really odd code. Just as we have CHECKs at the C/C++ layer, we should have some basic checks at the js layer to keep from footgunning ourselves.

IMHO assertions are valid when dealing with userland inputs. For an internal (and fairly simple) construct, coverage by unit tests should be sufficient.
Also there's the matter of disparity of those two cases (ERR_INVALID_ARG_TYPE and ERR_INVALID_ARRAY_LENGTH) VS the other 10s of error message formatters.

But anyway I'm removing my objection.

@jasnell
Copy link
Member Author

jasnell commented Sep 1, 2017

@BridgeAR
Copy link
Member

BridgeAR commented Sep 3, 2017

@jasnell do you mind changing the assert name to something else e.g. "internalAssert"? Otherwise I think it is a bit confusing that it is not the "real" assert module and no other functions are available.

@refack
Copy link
Contributor

refack commented Sep 4, 2017

@jasnell do you mind changing the assert name to something else e.g. "internalAssert"? Otherwise I think it is a bit confusing that it is not the "real" assert module and no other functions are available.

I just had the same though 🤔

@jasnell
Copy link
Member Author

jasnell commented Sep 5, 2017

Updated with the function renamed and a test fixed.

@jasnell
Copy link
Member Author

jasnell commented Sep 5, 2017

jasnell added a commit that referenced this pull request Sep 12, 2017
PR-URL: #15002
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@jasnell
Copy link
Member Author

jasnell commented Sep 12, 2017

Landed in 6ff521b

@jasnell jasnell closed this Sep 12, 2017
addaleax pushed a commit to addaleax/node that referenced this pull request Sep 13, 2017
PR-URL: nodejs#15002
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@jasnell
Copy link
Member Author

jasnell commented Sep 20, 2017

This will need to be backported for 8.x

jasnell added a commit to jasnell/node that referenced this pull request Sep 25, 2017
PR-URL: nodejs#15002
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
jasnell added a commit that referenced this pull request Sep 25, 2017
PR-URL: #15002
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants