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

errors: port internal/fs errors to internal/errors #11317

Merged
merged 1 commit into from Jul 19, 2017
Merged

Conversation

@gunar
Copy link
Contributor

@gunar gunar commented Feb 12, 2017

  • Assign codes to errors reported by internal/fs.js

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

errors, fs

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

This comment has been minimized.

@joyeecheung

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

This comment has been minimized.

@joyeecheung

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

This comment has been minimized.

@jasnell

jasnell Feb 13, 2017
Member

the code is set up to support either. this should be fine.

This comment has been minimized.

@gunar

gunar Feb 14, 2017
Author Contributor

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)

This comment has been minimized.

@thefourtheye

thefourtheye Feb 12, 2017
Contributor

Semicolon is missing at the end.

This comment has been minimized.

@gunar

gunar Feb 12, 2017
Author Contributor

Fixed.

@gunar gunar mentioned this pull request Feb 14, 2017
79 of 80 tasks complete
@gunar
Copy link
Contributor Author

@gunar gunar commented Feb 14, 2017

  1. At what moment should I squash my commits?
  2. Is there anything lacking in this PR as it is?

Thank you!

@joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Feb 14, 2017

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

@jasnell jasnell added the blocked label Apr 5, 2017
@refack refack force-pushed the nodejs:master branch to fbe946b Apr 14, 2017
@fhinkel
Copy link
Member

@fhinkel fhinkel commented May 23, 2017

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

Copy link
Member

@mhdawson mhdawson left a comment

LGTM

@fhinkel
Copy link
Member

@fhinkel fhinkel commented Jun 7, 2017

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.

@fhinkel fhinkel closed this Jun 7, 2017
@gunar
Copy link
Contributor Author

@gunar gunar commented Jun 19, 2017

Rebased, squashed, pushed to https://github.com/gunar/node/tree/internal-errors-fs.
Ready for review.
However, this PR did not get updated with the newest commits.
Guess it'll happen as soon as we reopen the PR.
@fhinkel Would you reopen it, please? Thanks

@joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Jun 19, 2017

@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).

@gunar gunar deleted the gunar:internal-errors-fs branch Jun 20, 2017
@gunar gunar restored the gunar:internal-errors-fs branch Jun 20, 2017
@gunar
Copy link
Contributor Author

@gunar gunar commented Jun 20, 2017

@joyeecheung Gotcha. Should be good to go now. Please reopen.

@mhdawson mhdawson reopened this Jun 20, 2017
@mhdawson
Copy link
Member

@mhdawson mhdawson commented Jun 20, 2017

reopened.

@refack refack mentioned this pull request Jun 21, 2017
3 of 3 tasks complete
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);

This comment has been minimized.

@BridgeAR

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.

This comment has been minimized.

@refack

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

This comment has been minimized.

@gunar

gunar Jun 21, 2017
Author Contributor

Agreed. Done.

Copy link
Member

@BridgeAR BridgeAR left a comment

LGTM with a nit that should be addressed before merging.

test/parallel/test-fs-assert-encoding-error.js Outdated
@@ -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');

This comment has been minimized.

@BridgeAR

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.

@gunar
Copy link
Contributor Author

@gunar gunar commented Jun 21, 2017

I think this is what you meant
Let me know otherwise

If all is good I'll squash the commits
Thanks!

@refack refack self-assigned this Jun 22, 2017
@refack
Copy link
Member

@refack refack commented Jun 23, 2017

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

This comment has been minimized.

@jasnell

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.

This comment has been minimized.

@refack

refack Jun 26, 2017
Member

IMHO if we specialize it should be ERR_INVALID_OPT_VALUE_ENCODING

This comment has been minimized.

@gunar

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.

This comment has been minimized.

@refack

refack Jun 28, 2017
Member

Go with ERR_INVALID_OPT_VALUE_ENCODING, I believe @jasnell will agree

This comment has been minimized.

@gunar

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.

This comment has been minimized.

@refack

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

@gunar
Copy link
Contributor Author

@gunar gunar commented Jun 28, 2017

@refack I can't seem to find the linting error
Shouldn't it be somewhere in the CI page?

@refack
Copy link
Member

@refack refack commented Jun 28, 2017

@refack I can't seem to find the linting error
Shouldn't it be somewhere in the CI page?

You should run make lint or vcbuild nobuild noprojgen lint

As for the CI, not yet, it's a todo... nodejs/build#720 but if you hit the machine just after it finishes the tap file is there:
https://ci.nodejs.org/job/node-test-linter/10114/

not ok 33 - /usr/home/iojs/build/workspace/node-test-linter/test/parallel/test-internal-fs.js
  ---
  message: Expected indentation of 14 spaces but found 2.
  severity: error
  data:
    line: 11
    column: 3
    ruleId: indent-legacy
  ...
@gunar
Copy link
Contributor Author

@gunar gunar commented Jun 29, 2017

Check 'em

@refack
Copy link
Member

@refack refack commented Jun 29, 2017

https://ci.nodejs.org/job/node-test-pull-request/8867/
https://ci.nodejs.org/job/node-test-commit/10819/

IMHO the PR is ready so I'm going to land it later today.
Since it's semver-major we have a ample time to decide if we want to revamp the error codes during the v9.x cooking timeframe...

@refack
Copy link
Member

@refack refack commented Jun 29, 2017

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)
@gunar
Copy link
Contributor Author

@gunar gunar commented Jun 29, 2017

I did forget one!
Disclaimer: I have Py3 on my machine so getting tests to run locally is tricky.

Let me know when it's good to squash
I rather have separate commits during dev

@gunar
Copy link
Contributor Author

@gunar gunar commented Jul 18, 2017

Is anything else required of me?
I'd like to get this merged :-)

@refack
Copy link
Member

@refack refack commented Jul 18, 2017

Is anything else required of me?
I'd like to get this merged :-)

I don't see anything else.
Pre-land CI: https://ci.nodejs.org/job/node-test-commit/11225/

@refack
Copy link
Member

@refack refack commented Jul 18, 2017

@gunar even though the end state has no conflicts with master is seems like the intermediate commits do, so could you squash and rebase?

From the CI machine:

+ git rebase --committer-date-is-author-date f406a7ebaee09c00b6dec330e17897924096c30d
First, rewinding head to replay your work on top of it...
Applying: errors: port internal/fs errors to internal/errors
Using index info to reconstruct a base tree...
M	doc/api/errors.md
M	lib/internal/errors.js
Falling back to patching base and 3-way merge...
Auto-merging lib/internal/errors.js
CONFLICT (content): Merge conflict in lib/internal/errors.js
Auto-merging doc/api/errors.md
CONFLICT (content): Merge conflict in doc/api/errors.md
Failed to merge in the changes.
Patch failed at 0001 errors: port internal/fs errors to internal/errors
The copy of the patch that failed is found in:
   /var/lib/jenkins/jobs/node-test-commit/workspace@6/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
@gunar
Copy link
Contributor Author

@gunar gunar commented Jul 19, 2017

Sure thing! There you go.

@refack
Copy link
Member

@refack refack commented Jul 19, 2017

Landed in 81084d47b5

@refack refack closed this Jul 19, 2017
@refack refack removed the blocked label Jul 19, 2017
@refack refack reopened this Jul 19, 2017
@refack refack closed this Jul 19, 2017
@refack
Copy link
Member

@refack refack commented Jul 19, 2017

@gunar Congrats on GitHub promoting you from:
image
To
image

@refack refack reopened this Jul 19, 2017
@refack
Copy link
Member

@refack refack commented Jul 19, 2017

* 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>
@refack refack merged commit b61cab2 into nodejs:master Jul 19, 2017
@gunar
Copy link
Contributor Author

@gunar gunar commented Jul 20, 2017

Siiiick. Thank, man!

@gunar gunar deleted the gunar:internal-errors-fs branch Jul 20, 2017
@refack refack removed their assignment Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

10 participants
You can’t perform that action at this time.