-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
// Flags: --expose-internals | ||
require('../common'); | ||
|
||
const assert = require('internal/assert'); | ||
assert(false); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
internal/assert.js:* | ||
throw new ERR_INTERNAL_ASSERTION(message); | ||
^ | ||
|
||
Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals. | ||
Please open an issue with this stack trace at https://github.com/nodejs/node/issues | ||
|
||
at assert (internal/assert.js:*:*) | ||
at * (*test*message*internal_assert.js:7:1) | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
// Flags: --expose-internals | ||
require('../common'); | ||
|
||
const assert = require('internal/assert'); | ||
assert.fail('Unreachable!'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
internal/assert.js:* | ||
throw new ERR_INTERNAL_ASSERTION(message); | ||
^ | ||
|
||
Error [ERR_INTERNAL_ASSERTION]: Unreachable! | ||
This is caused by either a bug in Node.js or incorrect usage of Node.js internals. | ||
Please open an issue with this stack trace at https://github.com/nodejs/node/issues | ||
|
||
at Function.fail (internal/assert.js:*:*) | ||
at * (*test*message*internal_assert_fail.js:7:8) | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
// This tests that the internal assert module works as expected. | ||
// The failures are tested in test/message. | ||
|
||
require('../common'); | ||
|
||
const assert = require('assert'); | ||
const internalAssert = require('internal/assert'); | ||
|
||
// Should not throw. | ||
internalAssert(true); | ||
internalAssert(true, 'fhqwhgads'); | ||
|
||
assert.throws(() => { internalAssert(false); }, assert.AssertionError); | ||
assert.throws(() => { internalAssert(false, 'fhqwhgads'); }, | ||
{ code: 'ERR_ASSERTION', message: 'fhqwhgads' }); | ||
assert.throws(() => { internalAssert.fail('fhqwhgads'); }, | ||
{ code: 'ERR_ASSERTION', message: 'fhqwhgads' }); |
This file contains 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
This file contains 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
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 otherexpectsSomething
to one file when the time comesThere was a problem hiding this comment.
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 :SThere was a problem hiding this comment.
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 useassert.throws()
instead. Only callbacks should always usecommon.expectsError()
.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 casetest/message/internal_assert.js
is enough), so there's no need for the value that you are DRYing in the first place.There was a problem hiding this comment.
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 patcheswatcher._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.There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.There was a problem hiding this comment.
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.