-
Notifications
You must be signed in to change notification settings - Fork 30k
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: port internal/fs errors to internal/errors #11317
Conversation
lib/internal/errors.js
Outdated
@@ -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'); |
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.
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
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.
Although util.format
strings should be more readable, and since we are throwing errors performance probably is not the primary concern here..
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 code is set up to support either. this should be fine.
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.
Even if both work, for consistency purposes we should commit to either one.
lib/internal/fs.js
Outdated
@@ -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) |
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.
Semicolon is missing at the end.
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.
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! |
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
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. |
lib/internal/fs.js
Outdated
@@ -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); |
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 recommend to use the ERR_INVALID_OPT_VALUE
error type for both cases here instead of creating new ones.
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 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;
}
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.
Agreed. Done.
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 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'); |
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 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. |
lib/internal/fs.js
Outdated
@@ -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); |
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.
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.
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.
IMHO if we specialize it should be ERR_INVALID_OPT_VALUE_ENCODING
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.
Makes sense. I don't think I am the one who should make the call. Let me know and I'll implement.
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.
Go with ERR_INVALID_OPT_VALUE_ENCODING
, I believe @jasnell will agree
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.
Friendly reminder: We went from ERR_UNKNOWN_ENCODING
to ERR_INVALID_OPT_VALUE
to ERR_INVALID_OPT_VALUE_ENCODING
.
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.
Friendly reminder: We went from
ERR_UNKNOWN_ENCODING
toERR_INVALID_OPT_VALUE
toERR_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