-
Notifications
You must be signed in to change notification settings - Fork 30k
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
fs,test: throw rather than assert if condition is possible #32028
Conversation
It is possible to make `.close()` assert on an FSWatcher if the `_handle` property is monkey-patched. Assertions should be reserved for things that are believed to be logically impossible. Since we know end users can cause the assertion, change it to a throw.
Remove convenience function for internal assertions. It is only used once.
Cover an previously uncovered exception possible in the internal start function for FSWatcher.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -163,7 +162,9 @@ FSWatcher.prototype[kFSWatchStart] = function(filename, | |||
if (this._handle === null) { // closed | |||
return; | |||
} | |||
assert(this._handle instanceof FSEvent, 'handle must be a FSEvent'); |
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 prefer to keep it as is. Use of assertions to ensure that requirements are met is a common pattern used by many languages. Also the ERR_UNEXPECTED_INSTANCE
custom error does not make sense in my opinion. It's an error that should not exist.
That said I won't block this if others are ok with removing assertions from the code base.
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.
prefer to keep it as is. Use of assertions to ensure that requirements are met is a common pattern used by many languages.
I certainly am not excited about adding another error code--wish we had vastly fewer codes--so could leave the assert() part alone. This PR would then just add the test case and remove the expectInternalAssertion() from common.
I’m feeling the same way as @lpinca – I’d prefer to keep these as assertions. Throwing a specific kind of error would make monkey-patching seem like a supported API feature. (Which it is not in this case.)
We do use assertions a lot in situations in which users can break them by monkey-patching or illegally accessing internals. |
I could leave the assert() part alone. This PR would then just add the test case and remove the expectInternalAssertion() from common (which is undocumented, unused in other tests, and trivially wraps assert.throws()).
Would you be in favor, at least in theory, of semver-major hardening things like what's in this PR to make them more difficult or impossible to monkey-patch? Or would there be concern that will just make life harder for APM folks? (Maybe they already have better options?) |
Closing in favor of #32057 which adds the test case and removes the |
Three commits:
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes