-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
internal/errors: improve invalid arg type #14057
Conversation
/cc @mscdex @joyeecheung @mhdawson, this is a fresh clone of #13834 PTAL |
received = String(actual); | ||
} else if (typeof actual === 'object') { | ||
if (actual.constructor != null) { | ||
received = `instance of ${actual.constructor.name}`; |
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.
Provided that actual
is an arbitrary user-provided object which we are validating, after this patch, exceptions can be raised on any of:
actual.constructor
access.actual.constructor.name
access.- String concatenation with
actual.constructor.name
(if it's aSymbol
orString(actual.constructor.name)
throws)
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.
This is an uncommon code path, so wrapping in try-catch
should be fine?
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 do not agree that it's useful to guard against a constructor or name property set to a getter that throws or being set to a symbol.
If this would ever result in an error, nothing bad would happen besides showing the "wrong" error.
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.
LGTM
For the error type ERR_INVALID_ARG_TYPE the expected type should be lower cased in case it's a primitive value. The actual value should always be present as it increases the provided error message information and it should not be passed to the error type as is. In addition this fixes some typos in the arguments names.
The error type ERR_INVALID_ARG_TYPE receives a actual value. Make that mandatory so the error message has more detailed information of what went wrong.
455dd27
to
1717cb9
Compare
Rebased due to conflicts (the commits will have to be squashed as it would be really tedious to make each commit pass). |
Unfortunately this now needs a rebase again. Thanks for your patience. |
Just as a note - I still plan on adding this but I decided to wait until all errors got ported. The reason was that it became really difficult to get this landed at that point of time due to lots of conflicting PRs. As we are almost through with the error codes, I am going to look into this soon again. |
@BridgeAR I think we are at a point where this PR can be revisited since most of the errors have now been ported |
@joyeecheung I would like to work on this again but I am not sure when I really get back to it. It is quite some significant work to refactor all those tests. Because of that reason I am closing the PR for now. I might get back to it again at another point. I definitely want to work more on improving our errors in general. |
Something went wrong with #13834
This is the original change as it should be.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
internal/errors