-
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
errors: extract type detection & use in ERR_INVALID_RETURN_VALUE
#43558
errors: extract type detection & use in ERR_INVALID_RETURN_VALUE
#43558
Conversation
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
Is there no test that requires an update?
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. We tend not to test for error messages because we want to be able to change them in semver-patch commits, it’s not surprising that there are no tests to update.
What were you saying @aduh95? 😆 I'll update that test tomorrow. |
c0fae42
to
74be6fe
Compare
determineSpecificType(Object.create(null)), | ||
'an instance of Object', |
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.
Well that's just untrue x) Object.create(null) instanceof Object === false
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.
Technically untrue, yes, but I think being helpful and a tiny bit wrong is better.
I had originally put 'an instance of Object (null Prototype)'
, but decided that was TMI; if I put that in, would it address your concern? (Or perhaps 'type object (null Prototype)'
or any other similar flavour)
Otherwise you end up with a error message like Expected an instance of Map, but instead got [Object: null prototype] {}
(which looks ugly and kind of confusing)
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.
Technically untrue, yes, but I think being helpful and a tiny bit wrong is better.
I very much disagree here, I feel quite strongly that error messages must always be technically correct first, to me I believe one can't be helpful if they are misleading.
I think it should not be special cased, type object ([Object: null prototype] {})
is good enough to me. What is it that you don't like about it exactly?
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 is it that you don't like about it exactly?
It looks bizarre before your suggested change below—it didn't have type
(I think it's better now with your suggestion), it was just got [Object: null prototype] {}
); type object (null Prototype)
seems more human-friendly to me, and similar to other type outputs (ex type number (2)
), but I can live with type object ([Object: null prototype] ...)
.
Note that the actual output with your suggestion below is type object ([Object: null prototype] ...)
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 definitely prefer the former output: limiting the string was only done for primitives and functions. Objects have not been inspected closer and just the most outer layer was inspected. That's not the case anymore and would possibly hide important information. The reason not to add type object
is that it should be obvious that it's an object as everything is that's not a primitive (or function). It was therefore a way to limit the output to the necessary information.
Please change that back.
…LUE` `new Array(0)` et al → new Array(); tag self in FIXME
…TURN_VALUE` type object (…)
…ALID_RETURN_VALUE` de-lint
@aduh95 @BridgeAR looks like there's a test helper in common that duplicates the functionality of the new Lines 732 to 749 in 42ad967
I think it should be de-duplicated. Would it be okay to import the new helper into test/common and re-export it? |
What about removing it? If we have tests for |
I think that's right thing to do in the end, but it's used in 104 places, most of which are using things like |
I agree it’s not something to do in this PR, so I guess my stance on it is we should leave it as is for now. |
Oow! That's good to know, but I think that isn't sufficient because it would do only 1 match, and there are multiple key words that need to match (the type it should've been and the type it received). I might have to update a whole lotta tests' message checks—test parallel is drip-feeding me the failures. |
I suggest to keep everything as is. The point to test internal error messages even for concrete errors is actually useful in a couple of cases where it's possible to pass through individual error message content. Yes, it's possible to use a regexp and that would mostly suffice while it would not always detect all issues. We do not have a downside by keeping it as is, so why do that? |
There is a downside to keeping it as is: it makes the tests rigid and brittle, and creates make-work for inconsequential changes. The error messages are the same aside from the keys words that matter and can change, so checking for those are all the actual matters downstream (especially when upstream tests already guarantee that they're the same). |
Commit Queue failed- Loading data for nodejs/node/pull/43558 ✔ Done loading data for nodejs/node/pull/43558 ----------------------------------- PR info ------------------------------------ Title errors: extract type detection & use in `ERR_INVALID_RETURN_VALUE` (#43558) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch JakobJingleheimer:errors/account-for-specific-types-in-return-value -> nodejs:main Labels errors, needs-ci, commit-queue-squash Commits 5 - errors: extract type detection & use in `ERR_INVALID_RETURN_VALUE` - fixup! errors: extract type detection & use in `ERR_INVALID_RETURN_VA… - fixup! fixup! errors: extract type detection & use in `ERR_INVALID_RE… - fixup! fixup! fixup! errors: extract type detection & use in `ERR_INV… - fixup! fixup! fixup! fixup! errors: extract type detection & use in `… Committers 1 - Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com> PR-URL: https://github.com/nodejs/node/pull/43558 Reviewed-By: Ruben Bridgewater Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/43558 Reviewed-By: Ruben Bridgewater Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last review: ⚠ - fixup! fixup! fixup! fixup! errors: extract type detection & use in `… ℹ This PR was created on Fri, 24 Jun 2022 10:16:18 GMT ✔ Approvals: 3 ✔ - Ruben Bridgewater (@BridgeAR) (TSC): https://github.com/nodejs/node/pull/43558#pullrequestreview-1018314632 ✔ - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/43558#pullrequestreview-1018326931 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/43558#pullrequestreview-1020506108 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2022-06-24T11:31:50Z: https://ci.nodejs.org/job/node-test-pull-request/44830/ ⚠ Commits were pushed after the last Full PR CI run: ⚠ - errors: extract type detection & use in `ERR_INVALID_RETURN_VALUE` ⚠ - fixup! errors: extract type detection & use in `ERR_INVALID_RETURN_VA… ⚠ - fixup! fixup! errors: extract type detection & use in `ERR_INVALID_RE… ⚠ - fixup! fixup! fixup! errors: extract type detection & use in `ERR_INV… ⚠ - fixup! fixup! fixup! fixup! errors: extract type detection & use in `… - Querying data for job/node-test-pull-request/44830/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/2594944073 |
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.
Please do not change the message for objects without constructor (name).
@BridgeAR can you clarify why? Is it because you worry it might be too breaking or because you think the new message is worse? |
@aduh95 the latter. |
@BridgeAR sorry! I didn't mean to sneak something through. Antoine was online, so I DM'd him to ask how to unblock this PR (which is blocking an esm bugfix), and it seemed I had misunderstood your objection (but apparently not). I mentioned your opposition a few times in the above comments, and the dialogue spanned a couple days without you chiming in (and you had approved and didn't change it), so I thought I'd misinterpreted your comments. I'll revert the change to objects without a constructor name. |
…se in `ERR_INVALID_RETURN_VALUE` revert type determination output for objects without a constructor
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.
Thanks!
test/common/index.js
Outdated
@@ -737,14 +737,15 @@ function invalidArgTypeHelper(input) { | |||
return ` Received function ${input.name}`; | |||
} | |||
if (typeof input === 'object') { | |||
if (input.constructor && input.constructor.name) { | |||
if (input?.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.
if (input?.constructor?.name) { | |
if (input.constructor?.name) { |
We know for certain that input
is an object of some kind (null is already checked above).
lib/internal/errors.js
Outdated
return `function ${value.name}`; | ||
} | ||
if (typeof value === 'object') { | ||
if (value?.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.
if (value?.constructor?.name) { | |
if (value.constructor?.name) { |
…ion & use in `ERR_INVALID_RETURN_VALUE` remove superfluous optional property access on constructor
Commit Queue failed- Loading data for nodejs/node/pull/43558 ✔ Done loading data for nodejs/node/pull/43558 ----------------------------------- PR info ------------------------------------ Title errors: extract type detection & use in `ERR_INVALID_RETURN_VALUE` (#43558) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch JakobJingleheimer:errors/account-for-specific-types-in-return-value -> nodejs:main Labels errors, needs-ci, commit-queue-squash Commits 7 - errors: extract type detection & use in `ERR_INVALID_RETURN_VALUE` - fixup! errors: extract type detection & use in `ERR_INVALID_RETURN_VA… - fixup! fixup! errors: extract type detection & use in `ERR_INVALID_RE… - fixup! fixup! fixup! errors: extract type detection & use in `ERR_INV… - fixup! fixup! fixup! fixup! errors: extract type detection & use in `… - fixup! fixup! fixup! fixup! fixup! errors: extract type detection & u… - fixup! fixup! fixup! fixup! fixup! fixup! errors: extract type detect… Committers 1 - Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com> PR-URL: https://github.com/nodejs/node/pull/43558 Reviewed-By: Ruben Bridgewater Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/43558 Reviewed-By: Ruben Bridgewater Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last review: ⚠ - fixup! fixup! fixup! fixup! fixup! fixup! errors: extract type detect… ℹ This PR was created on Fri, 24 Jun 2022 10:16:18 GMT ✔ Approvals: 3 ✔ - Ruben Bridgewater (@BridgeAR) (TSC): https://github.com/nodejs/node/pull/43558#pullrequestreview-1026202846 ✔ - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/43558#pullrequestreview-1018326931 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/43558#pullrequestreview-1020506108 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2022-07-01T07:07:35Z: https://ci.nodejs.org/job/node-test-pull-request/44830/ ⚠ Commits were pushed after the last Full PR CI run: ⚠ - fixup! fixup! fixup! fixup! fixup! errors: extract type detection & u… ⚠ - fixup! fixup! fixup! fixup! fixup! fixup! errors: extract type detect… - Querying data for job/node-test-pull-request/44830/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/2598011811 |
Landed in 5a18304 |
PR-URL: #43558 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #43558 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #43558 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs/node#43558 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Address issues in error messaging like when
value
isnull
(error message previously says something to the effect ofexpected an object […] but got an object
).