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

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

merged 1 commit into from
Jul 19, 2017

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

@nodejs-github-bot nodejs-github-bot added errors Issues and PRs related to JavaScript errors originated in Node.js core. fs Issues and PRs related to the fs subsystem / file system. labels Feb 12, 2017
@TimothyGu TimothyGu added the semver-major PRs that contain breaking changes and should be released in the next major version. label Feb 12, 2017
@@ -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');
Copy link
Member

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

Copy link
Member

@joyeecheung joyeecheung Feb 12, 2017

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

Copy link
Member

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.

Copy link
Contributor Author

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.

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@TimothyGu
Copy link
Member

@gunar
Copy link
Contributor Author

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

@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 PRs that are blocked by other issues or PRs. label Apr 5, 2017
@fhinkel
Copy link
Member

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fhinkel
Copy link
Member

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 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 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 internal-errors-fs branch June 20, 2017 13:25
@gunar gunar restored the internal-errors-fs branch June 20, 2017 13:25
@gunar
Copy link
Contributor Author

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

reopened.

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

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Done.

Copy link
Member

@BridgeAR BridgeAR left a 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');
Copy link
Member

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.

@gunar
Copy link
Contributor Author

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
@mhdawson
Copy link
Member

@refack
Copy link
Contributor

refack commented Jun 23, 2017

@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);
Copy link
Member

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

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

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 commented Jun 29, 2017

Check 'em

@refack
Copy link
Contributor

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
Contributor

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 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 commented Jul 18, 2017

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

@refack
Copy link
Contributor

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
Contributor

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 commented Jul 19, 2017

Sure thing! There you go.

@refack
Copy link
Contributor

refack commented Jul 19, 2017

Landed in 81084d47b5

@refack refack closed this Jul 19, 2017
@refack refack removed the blocked PRs that are blocked by other issues or PRs. label Jul 19, 2017
@refack refack reopened this Jul 19, 2017
@refack refack closed this Jul 19, 2017
@refack
Copy link
Contributor

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
Contributor

refack commented Jul 19, 2017

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

gunar commented Jul 20, 2017

Siiiick. Thank, man!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. fs Issues and PRs related to the fs subsystem / file system. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants