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

lib: throw a special error in internal/assert #26635

Closed
wants to merge 2 commits into from

Conversation

joyeecheung
Copy link
Member

Instead of using the public AssertionError, use a simplified
error that describes potential causes of these assertions
and suggests the user to open an issue.

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

@nodejs-github-bot nodejs-github-bot added assert Issues and PRs related to the assert subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core. labels Mar 13, 2019
Copy link
Member

@BridgeAR BridgeAR 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 would just rather not use the helper function.

name: 'Error [ERR_INTERNAL_ASSERTION]',
code: 'ERR_INTERNAL_ASSERTION'
});
}
Copy link
Member

Choose a reason for hiding this comment

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

I would rather not add this helper function in common. Common is AFAIC pretty overboarded.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's where common.expectsError is...I guess we could move these and other expectsSomething to one file when the time comes

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, surprisingly, test/common.js is even less than 1000 lines? That's even smaller than a lot of our tests :S

Copy link
Member

Choose a reason for hiding this comment

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

It's not about having a lot of lines but this file is loaded for every single test file and I would rather completely get rid of something that we always use.

Having something more specific would be fine but I actually doubt that this will often be tested for and currently there are only for places in which this helper would be used in.

About common.expectsError() it is already used significantly less as we can always use assert.throws() instead. Only callbacks should always use common.expectsError().

Copy link
Member

Choose a reason for hiding this comment

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

Do you strongly prefer the helper function? To me it still does not seem necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the consensus is you don't need to validate the message of errors in more then one place (in this case test/message/internal_assert.js is enough), so there's no need for the value that you are DRYing in the first place.

Copy link
Member Author

@joyeecheung joyeecheung Mar 31, 2019

Choose a reason for hiding this comment

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

@refack This is special in that the message is what we want to test for in the test cases, because the code is constant across all internal assertions and we intentionally do not give error codes for assertions coming out of completely different type of bugs.

For instance, we want to verify that we tell the user handle must be a FSEvent if the user monkey patches watcher._handle incorrectly, but we do not want to create a code for that special type of bugs because the user is simply violating the API contract and it gives us little to classify all these violations and assign permanent error codes instead of just telling them no. However it's still useful to verify that we hint something helpful in the message.

Copy link
Member Author

@joyeecheung joyeecheung Mar 31, 2019

Choose a reason for hiding this comment

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

I think it's important to make sure we provide useful information in the assertions, even for our own sake - just making sure that we say "you are hitting a bug, please open an issue" is not enough, see all the useless error messages in #26798 before #26859 (though that one is not verifiable in user land).

Copy link
Contributor

Choose a reason for hiding this comment

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

This is special in that the message is what we want to test for in the test cases,

What I mean there's no need to validate the message formatting mechanism more then once.
For example you can store the specific prefix behind a Symbol field and validate just it.

Copy link
Member

Choose a reason for hiding this comment

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

My concern about common/index is only about the requirement of a common helper function. I would love to remove the requirement for our test files at some point.

I already gave my LG, so from my side this can land as is.

doc/api/errors.md Outdated Show resolved Hide resolved
@joyeecheung
Copy link
Member Author

Rebased & addressed doc reviews: https://ci.nodejs.org/job/node-test-pull-request/21638/

@BridgeAR
Copy link
Member

@joyeecheung this requires a rebase.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@joyeecheung
Copy link
Member Author

Made the paths in message tests play nice with Windows

@nodejs-github-bot
Copy link
Collaborator

@refack
Copy link
Contributor

refack commented Mar 31, 2019

I'm thinking about this some more... I believe this is a big change that deserves some design review. For example:

  • Are these exceptions recoverable? Maybe they should crash the process?
  • If the message is unique we are circling back to the if (e.message is something) { something specific } issue... How do we avoid that?

So essentially IMO this is a semver-major change...

@joyeecheung
Copy link
Member Author

TBH this is just a drive-by change for me, what I had in mind is more along the lines of “oh, this is entirely internal, why not just say something more helpful, we should be free to change this and are totally free to regret about it if it’s a bad idea”. I don’t personally think it’s worth the time to be pedantic about it, so if anyone has any strong opinions about what’s changed here, feel free to take it on.

@BridgeAR
Copy link
Member

BridgeAR commented Apr 3, 2019

@refack I definitely disagree that this is semver-major. If anyone runs into one of these assertions, something must be seriously broken. We only use the assertions as safeguards without documenting any of them as in giving a guarantee for the error message.

It is also out of scope of this PR if the exceptions are recoverable or not. That could be looked at in another PR or issue but that's definitely something independent for me.

@BridgeAR
Copy link
Member

BridgeAR commented Apr 7, 2019

@refack is your comment blocking? If not, I'd actually like to go ahead and land this as is.

@BridgeAR BridgeAR added the review wanted PRs that need reviews. label Apr 9, 2019
@BridgeAR
Copy link
Member

BridgeAR commented Apr 9, 2019

I would actually like to land this some time soon. @refack is your comment blocking?

@BridgeAR
Copy link
Member

I'll land this on the 16.04. if there's no hard objection until then. // @refack

BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Apr 22, 2019
Instead of using the public AssertionError, use a simplified
error that describes potential causes of these assertions
and suggests the user to open an issue.

PR-URL: nodejs#26635
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@BridgeAR
Copy link
Member

BridgeAR commented Apr 22, 2019

Landed in e9022df 🎉

@BridgeAR BridgeAR closed this Apr 22, 2019
@BridgeAR
Copy link
Member

I had to force push this out again, since the tests failed due to recent changes.

@BridgeAR BridgeAR reopened this Apr 22, 2019
joyeecheung and others added 2 commits April 22, 2019 17:47
Instead of using the public AssertionError, use a simplified
error that describes potential causes of these assertions
and suggests the user to open an issue.
@nodejs-github-bot
Copy link
Collaborator

@BridgeAR
Copy link
Member

Landed in b9f1e57 🎉

@BridgeAR BridgeAR closed this Apr 24, 2019
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Apr 24, 2019
Instead of using the public AssertionError, use a simplified
error that describes potential causes of these assertions
and suggests the user to open an issue.

PR-URL: nodejs#26635
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
targos pushed a commit that referenced this pull request Apr 27, 2019
Instead of using the public AssertionError, use a simplified
error that describes potential causes of these assertions
and suggests the user to open an issue.

PR-URL: #26635
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@targos targos mentioned this pull request Apr 27, 2019
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. errors Issues and PRs related to JavaScript errors originated in Node.js core. review wanted PRs that need reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants