-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
crypto: extract throwInvalidArgType function #22947
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
Conversation
|
Not opposed to this change, but the name |
Yeah, I agree. I was struggling to come up with a good name. Let me try to come up with a better name for the function. |
lib/internal/crypto/cipher.js
Outdated
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 change seems like a mistake. The toBuf() function accepts a string and transform that into a buffer.
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.
The motivation for this changes was that toBuf() would convert any string passed in to a Buffer, and therefore isArrayBufferView would not be passed a string for the password, key, and iv cases.
Note that my first commit also updated the update function which does not call toBuf() which was a mistake and this as fixed in the latest commit, so update will also include the string in its throws cause.
Does that still sound incorrect?
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.
The error message corresponds to the possible values for the user, not to possible transformations we do internally before throwing the error. So string should still be valid in all of these cases.
lib/internal/crypto/cipher.js
Outdated
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.
Nit: I would prefer constructing the error object in the function and throwing it explicitly here. I think it would be better during the reviews and one less line in the stack trace 😉.
Sorry, something went wrong.
All reactions
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.
That makes sense. I'll update shortly. Thanks!
Sorry, something went wrong.
All reactions
|
New CI: https://ci.nodejs.org/job/node-test-pull-request/17419/ |
All reactions
Sorry, something went wrong.
|
Re-run of failing node-test-commit-smartos and node-test-commit-linux. |
All reactions
Sorry, something went wrong.
This commit extracts the throwing of ERR_INVALID_ARG_TYPE which is done in identical ways in a few places in cipher.js. The motivation for this is that I think it improves readability enough to warrant a commit even though I'm aware that we should avoid commits with only these sort of refactoring.
0c53f0e to
310ed4f
Compare
|
Rebased CI: https://ci.nodejs.org/job/node-test-pull-request/17461/ |
All reactions
Sorry, something went wrong.
|
New CI: https://ci.nodejs.org/job/node-test-pull-request/17579/ |
All reactions
Sorry, something went wrong.
|
Re-run of failing node-test-commit-arm |
All reactions
Sorry, something went wrong.
This commit extracts the throwing of ERR_INVALID_ARG_TYPE which is done in identical ways in a few places in cipher.js. The motivation for this is that I think it improves readability enough to warrant a commit even though I'm aware that we should avoid commits with only these sort of refactoring. PR-URL: #22947 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit extracts the throwing of ERR_INVALID_ARG_TYPE which is done in identical ways in a few places in cipher.js. The motivation for this is that I think it improves readability enough to warrant a commit even though I'm aware that we should avoid commits with only these sort of refactoring. PR-URL: #22947 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit extracts the throwing of ERR_INVALID_ARG_TYPE which is done in identical ways in a few places in cipher.js. The motivation for this is that I think it improves readability enough to warrant a commit even though I'm aware that we should avoid commits with only these sort of refactoring. PR-URL: #22947 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewers
jasnell
addaleax
tniessen
BridgeAR
+1 more reviewer
thefourtheye
Assignees
No one assignedLabels
Projects
Milestone
No milestoneDevelopment
Successfully merging this pull request may close these issues.
This commit extracts the throwing of ERR_INVALID_ARG_TYPE which is done
in identical ways in a few places in cipher.js.
The motivation for this is that I think it improves readability enough to
warrant a commit even though I'm aware that we should avoid commits with
only these sort of refactoring.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes