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
Member

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
@lpinca

This comment has been minimized.

@lpinca
lpinca approved these changes Dec 18, 2018
@Trott

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

commented Dec 27, 2018

Ping @aoberoi

@aoberoi aoberoi force-pushed the aoberoi:fix-util.inherits-arg-type-error-message branch from ca22693 to 4ce3523 Dec 28, 2018

@aoberoi aoberoi force-pushed the aoberoi:fix-util.inherits-arg-type-error-message branch from 4ce3523 to fe1e8ea Dec 28, 2018

@aoberoi

This comment has been minimized.

Copy link
Member Author

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);

This comment has been minimized.

Copy link
@BridgeAR

BridgeAR Dec 28, 2018

Member
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.

This comment has been minimized.

Copy link
@aoberoi

aoberoi Dec 28, 2018

Author Member

@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

This comment has been minimized.

Copy link
Member Author

commented Jan 3, 2019

Ping @Trott

@Trott

This comment has been minimized.

@aoberoi

This comment has been minimized.

Copy link
Member Author

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

This comment has been minimized.

Copy link
Member

commented Jan 4, 2019

@addaleax

This comment has been minimized.

Copy link
Member

commented Jan 7, 2019

Ping @BridgeAR

@addaleax

This comment has been minimized.

Copy link
Member

commented Jan 14, 2019

Landed in eb5aab2, thanks for the PR!

@addaleax addaleax closed this Jan 14, 2019

addaleax added a commit that referenced this pull request Jan 14, 2019
util: fixes type in argument type validation error
PR-URL: #25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
addaleax added a commit to addaleax/node that referenced this pull request Jan 14, 2019
util: fixes type in argument type validation error
PR-URL: nodejs#25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
addaleax added a commit that referenced this pull request Jan 15, 2019
util: fixes type in argument type validation error
PR-URL: #25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@BridgeAR BridgeAR referenced this pull request Jan 16, 2019
BridgeAR added a commit to BridgeAR/node that referenced this pull request Jan 16, 2019
util: fixes type in argument type validation error
PR-URL: nodejs#25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@MylesBorins MylesBorins referenced this pull request Jan 24, 2019
BethGriggs added a commit that referenced this pull request Apr 29, 2019
util: fixes type in argument type validation error
PR-URL: #25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@BethGriggs BethGriggs referenced this pull request May 1, 2019
BethGriggs added a commit that referenced this pull request May 10, 2019
util: fixes type in argument type validation error
PR-URL: #25103
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MylesBorins added a commit that referenced this pull request May 16, 2019
util: fixes type in argument type validation error
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
Projects
None yet
6 participants
You can’t perform that action at this time.