Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
errors: port internal/fs errors to internal/errors #11317
Conversation
| @@ -86,3 +86,5 @@ module.exports = exports = { | |||
| // Note: Please try to keep these in alphabetical order | |||
| E('ERR_ASSERTION', (msg) => msg); | |||
| // Add new errors from here... | |||
| E('ERR_UNK_FILE_OPEN_FLAG', 'Unknown file open flag: %s'); | |||
joyeecheung
Feb 12, 2017
Member
Hmm, do we have a preference between util.format strings and arrow functions + templates? I think the latter should be more performant though(haven't tested) @jasnell
Hmm, do we have a preference between util.format strings and arrow functions + templates? I think the latter should be more performant though(haven't tested) @jasnell
joyeecheung
Feb 12, 2017
•
Member
Although util.format strings should be more readable, and since we are throwing errors performance probably is not the primary concern here..
Although util.format strings should be more readable, and since we are throwing errors performance probably is not the primary concern here..
jasnell
Feb 13, 2017
Member
the code is set up to support either. this should be fine.
the code is set up to support either. this should be fine.
gunar
Feb 14, 2017
Author
Contributor
Even if both work, for consistency purposes we should commit to either one.
Even if both work, for consistency purposes we should commit to either one.
| @@ -17,7 +18,7 @@ const O_WRONLY = constants.O_WRONLY | 0; | |||
|
|
|||
| function assertEncoding(encoding) { | |||
| if (encoding && !Buffer.isEncoding(encoding)) { | |||
| throw new Error(`Unknown encoding: ${encoding}`); | |||
| throw new errors.Error('ERR_UNK_ENCODING', encoding) | |||
thefourtheye
Feb 12, 2017
Contributor
Semicolon is missing at the end.
Semicolon is missing at the end.
gunar
Feb 12, 2017
Author
Contributor
Fixed.
Fixed.
Thank you! |
|
@gunar I think this can be squashed by whoever lands this. This PR needs a CITGM run though I am not sure if the CITGM CI works at the moment? |
|
@gunar Thanks so much for putting this together. Sorry that it is dragging out for so long due to being a semver-major change. Could you rebase and also squash your commits (I think all the changes should be one commit, right?). Thanks! |
|
LGTM |
|
I'm closing this because it's been inactive for quite a while. Feel free to reopen or ping a collaborator to get it reopened if needed. |
|
Rebased, squashed, pushed to https://github.com/gunar/node/tree/internal-errors-fs. |
|
@gunar This PR can not be reopened with a rebased branch (GitHub does not allow that), you can follow isaacs/github#361 (comment) to reopen it by moving the branch to where it was first, then reopen, then rebase again (the order makes a difference). |
|
@joyeecheung Gotcha. Should be good to go now. Please reopen. |
|
reopened. |
| @@ -52,7 +53,7 @@ function stringToFlags(flag) { | |||
| case 'xa+': return O_APPEND | O_CREAT | O_RDWR | O_EXCL; | |||
| } | |||
|
|
|||
| throw new Error('Unknown file open flag: ' + flag); | |||
| throw new errors.Error('ERR_UNK_FILE_OPEN_FLAG', flag); | |||
BridgeAR
Jun 21, 2017
Member
I recommend to use the ERR_INVALID_OPT_VALUE error type for both cases here instead of creating new ones.
I recommend to use the ERR_INVALID_OPT_VALUE error type for both cases here instead of creating new ones.
refack
Jun 21, 2017
Member
I second.
IMHO the special case is little bit counterproductive:
try {
// do some stuff
var f = fs.openSync('g.txt', 'rgh');
// do other stuff
catch (e) {
if (e.code == 'ERR_INVALID_OPT_VALUE') ; // swallow because I'm a special kind of guy
else throw e;
}
I second.
IMHO the special case is little bit counterproductive:
try {
// do some stuff
var f = fs.openSync('g.txt', 'rgh');
// do other stuff
catch (e) {
if (e.code == 'ERR_INVALID_OPT_VALUE') ; // swallow because I'm a special kind of guy
else throw e;
}
gunar
Jun 21, 2017
Author
Contributor
Agreed. Done.
Agreed. Done.
|
LGTM with a nit that should be addressed before merging. |
| @@ -4,72 +4,72 @@ const assert = require('assert'); | |||
| const fs = require('fs'); | |||
|
|
|||
| const options = 'test'; | |||
| const unknownEncodingMessage = /^Error: Unknown encoding: test$/; | |||
| const expectedError = common.expectsError('ERR_INVALID_OPT_VALUE'); | |||
BridgeAR
Jun 21, 2017
Member
Please also check for the type as this is not done anymore with the current check. Please change this in all the test files accordingly.
Please also check for the type as this is not done anymore with the current check. Please change this in all the test files accordingly.
|
I think this is what you meant If all is good I'll squash the commits |
|
@gunar there's a lint error. |
| @@ -18,16 +19,16 @@ const { | |||
|
|
|||
| function assertEncoding(encoding) { | |||
| if (encoding && !Buffer.isEncoding(encoding)) { | |||
| throw new Error(`Unknown encoding: ${encoding}`); | |||
| throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'encoding', encoding); | |||
jasnell
Jun 26, 2017
Member
Definitely prefer a more specific error for Unknown encoding. We throw these in several places throughout the source, often enough that it makes sense to identify them separately.
Definitely prefer a more specific error for Unknown encoding. We throw these in several places throughout the source, often enough that it makes sense to identify them separately.
refack
Jun 26, 2017
Member
IMHO if we specialize it should be ERR_INVALID_OPT_VALUE_ENCODING
IMHO if we specialize it should be ERR_INVALID_OPT_VALUE_ENCODING
gunar
Jun 28, 2017
Author
Contributor
Makes sense. I don't think I am the one who should make the call. Let me know and I'll implement.
Makes sense. I don't think I am the one who should make the call. Let me know and I'll implement.
gunar
Jun 29, 2017
Author
Contributor
Friendly reminder: We went from ERR_UNKNOWN_ENCODING to ERR_INVALID_OPT_VALUE to ERR_INVALID_OPT_VALUE_ENCODING.
Friendly reminder: We went from ERR_UNKNOWN_ENCODING to ERR_INVALID_OPT_VALUE to ERR_INVALID_OPT_VALUE_ENCODING.
refack
Jun 29, 2017
Member
Friendly reminder: We went from ERR_UNKNOWN_ENCODING to ERR_INVALID_OPT_VALUE to ERR_INVALID_OPT_VALUE_ENCODING.
I'm sorry to have made you run around... The new Error concept still has some undecided cases, you are just one of the first to tackle them...
Friendly reminder: We went from
ERR_UNKNOWN_ENCODINGtoERR_INVALID_OPT_VALUEtoERR_INVALID_OPT_VALUE_ENCODING.
I'm sorry to have made you run around... The new Error concept still has some undecided cases, you are just one of the first to tackle them...
|
@refack I can't seem to find the linting error |
You should run As for the CI, not yet, it's a todo... nodejs/build#720 but if you hit the machine just after it finishes the
|
|
Check 'em |
|
IMHO the PR is ready so I'm going to land it later today. |
|
Missed one: 761 parallel/test-internal-fs
duration_ms 0.59
severity fail
stack
assert.js:60
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: 'ERR_INVALID_OPT_VALUE_ENCODING' === 'ERR_INVALID_OPT_VALUE'
at Object.<anonymous> (/data/iojs/build/workspace/node-test-commit-linuxone/nodes/rhel72-s390x/test/common/index.js:701:12)
at expectedException (assert.js:520:19)
at _throws (assert.js:568:8)
at Function.throws (assert.js:577:3)
at Object.<anonymous> (/data/iojs/build/workspace/node-test-commit-linuxone/nodes/rhel72-s390x/test/parallel/test-internal-fs.js:10:8)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3) |
|
I did forget one! Let me know when it's good to squash |
|
Is anything else required of me? |
I don't see anything else. |
|
@gunar even though the end state has no conflicts with From the CI machine:
|
|
Sure thing! There you go. |
|
Landed in 81084d47b5 |
|
@gunar Congrats on GitHub promoting you from: |
|
Pulled out and re-running CI: https://ci.nodejs.org/job/node-test-commit/11245/ |
* Assign codes to errors reported by internal/fs.js PR-URL: #11317 Refs: #11273 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
|
Siiiick. Thank, man! |


Ref: #11273
Semver-major because this updates specific error messages and converts errors over to use the new internal/errors.js mechanism.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
errors, fs