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

util: fixes type in argument type validation error #25103

Conversation

aoberoi
Copy link
Contributor

@aoberoi aoberoi commented Dec 18, 2018

The argument validation for superCtor should not output that superCtor.prototype
must be a Function, but rather it must be an Object.

Checklist

@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label Dec 18, 2018
@lpinca
Copy link
Member

lpinca commented Dec 18, 2018

@Trott
Copy link
Member

Trott commented Dec 19, 2018

Test needs updating for this change.

12:54:18 not ok 2000 parallel/test-util-inherits
12:54:18   ---
12:54:18   duration_ms: 0.136
12:54:18   severity: fail
12:54:18   exitcode: 1
12:54:18   stack: |-
12:54:18     /Users/iojs/build/workspace/node-test-commit-osx/nodes/osx1011/test/common/index.js:580
12:54:18             throw new assert.AssertionError({
12:54:18             ^
12:54:18     
12:54:18     AssertionError [ERR_ASSERTION]: Expected "actual" to be reference-equal to "expected":
12:54:18     + actual - expected
12:54:18     
12:54:18       Comparison {
12:54:18         code: 'ERR_INVALID_ARG_TYPE',
12:54:18     +   message: 'The "superCtor.prototype" property must be of type Object. Received type undefined',
12:54:18     -   message: 'The "superCtor.prototype" property must be of type Function. Received type undefined',
12:54:18         type: [Function: TypeError]
12:54:18       }
12:54:18         at new AssertionError (internal/assert.js:396:11)
12:54:18         at Object.innerFn (/Users/iojs/build/workspace/node-test-commit-osx/nodes/osx1011/test/common/index.js:580:15)
12:54:18         at expectedException (assert.js:568:19)
12:54:18         at expectsError (assert.js:663:16)
12:54:18         at Function.throws (assert.js:694:3)
12:54:18         at Object.expectsError (/Users/iojs/build/workspace/node-test-commit-osx/nodes/osx1011/test/common/index.js:592:12)
12:54:18         at Object.<anonymous> (/Users/iojs/build/workspace/node-test-commit-osx/nodes/osx1011/test/parallel/test-util-inherits.js:86:8)
12:54:18         at Module._compile (internal/modules/cjs/loader.js:718:30)
12:54:18         at Object.Module._extensions..js (internal/modules/cjs/loader.js:729:10)
12:54:18         at Module.load (internal/modules/cjs/loader.js:617:32)
12:54:18   ...

@BridgeAR
Copy link
Member

Ping @aoberoi

@aoberoi aoberoi force-pushed the fix-util.inherits-arg-type-error-message branch from ca22693 to 4ce3523 Compare December 28, 2018 01:40
@aoberoi aoberoi force-pushed the fix-util.inherits-arg-type-error-message branch from 4ce3523 to fe1e8ea Compare December 28, 2018 02:00
@aoberoi
Copy link
Contributor Author

aoberoi commented Dec 28, 2018

fixed!

cc @BridgeAR, @Trott, @lpinca

@@ -317,7 +317,7 @@ function inherits(ctor, superCtor) {

if (superCtor.prototype === undefined) {
throw new ERR_INVALID_ARG_TYPE('superCtor.prototype',
'Function', superCtor.prototype);
'Object', superCtor.prototype);
Copy link
Member

@BridgeAR BridgeAR Dec 28, 2018

Choose a reason for hiding this comment

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

Suggested change
'Object', superCtor.prototype);
['Object', 'Function'], superCtor.prototype);

ECMAScript does not distinguish objects and functions but users do. Both will be accepted and all other inputs (besides null) throw.

I personally would either say we should remove the check to align the error message with the one for primitives or we should check for those as well. However, that would be semver-major and this function is already deprecated, so there's probably not much point in doing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@BridgeAR thanks for the review! i'm excited to land a commit 😄

I don't agree with the suggested change because the value of superCtor.prototype must be an object. Sure, a function is an object so that works, but its not the function-ness of this value that is important, it is the object-ness (the intention is that this value's properties become available in the prototype chain, that's an object-y aspect of this value). I could apply your reasoning here and say that the suggested change should include Array, RegExp, etc, since they are also all objects and are equally meaningful here as Function, but I think you see that it wouldn't make the error any more meaningful to include those.

Also, I'm not sure which function you mean is deprecated. From the public docs, I don't see any deprecation for util.inherits(). Do you mean that ERR_INVALID_ARG_TYPE() is deprecated? If so, what is the more favorable alternative?

Thanks for your help!

@aoberoi
Copy link
Contributor Author

aoberoi commented Jan 3, 2019

Ping @Trott

@Trott
Copy link
Member

Trott commented Jan 4, 2019

@aoberoi
Copy link
Contributor Author

aoberoi commented Jan 4, 2019

I see a couple build errors, but I don't think they are related to this change. Those seem to both be related to Worker Threads. Are they known to be flaky?

Possibly related: #21246

@Trott
Copy link
Member

Trott commented Jan 4, 2019

Resume Build CI: https://ci.nodejs.org/job/node-test-pull-request/19927/

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 7, 2019
@addaleax
Copy link
Member

addaleax commented Jan 7, 2019

Ping @BridgeAR

@addaleax
Copy link
Member

Landed in eb5aab2, thanks for the PR!

@addaleax addaleax closed this Jan 14, 2019
addaleax pushed a commit that referenced this pull request Jan 14, 2019
PR-URL: #25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
addaleax pushed a commit to addaleax/node that referenced this pull request Jan 14, 2019
PR-URL: nodejs#25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
addaleax pushed a commit that referenced this pull request Jan 15, 2019
PR-URL: #25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@BridgeAR BridgeAR mentioned this pull request Jan 16, 2019
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Jan 16, 2019
PR-URL: nodejs#25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@MylesBorins MylesBorins mentioned this pull request Jan 24, 2019
BethGriggs pushed a commit that referenced this pull request Apr 29, 2019
PR-URL: #25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@BethGriggs BethGriggs mentioned this pull request May 1, 2019
BethGriggs pushed a commit that referenced this pull request May 10, 2019
PR-URL: #25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MylesBorins pushed a commit that referenced this pull request May 16, 2019
PR-URL: #25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants