Skip to content

fs: migrate more errors to internal/errors - #17667

Closed
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:fs-migrate-internal-errors-2
Closed

fs: migrate more errors to internal/errors#17667
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:fs-migrate-internal-errors-2

Conversation

@jasnell

@jasnelljasnell commented Dec 14, 2017

Copy link
Copy Markdown
Member

Next batch of fs type checking migrations to use internal/errors

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)

fs

@jasnelljasnell added 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. labels Dec 14, 2017
@jasnell
jasnellforce-pushed the fs-migrate-internal-errors-2 branch from 2b87e7d to 0e284e1CompareDecember 14, 2017 01:01
@jasnelljasnell added the errors Issues and PRs related to JavaScript errors originated in Node.js core. label Dec 14, 2017
@jasnell

Copy link
Copy Markdown
MemberAuthor

Comment threaddoc/api/errors.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suspect this principle has been decided previously, but maybe not?:

Is it desirable to have such specific codes? Why not just ERR_INVALID_ARG_VALUE?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

it's been debated and I'm good with it either way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd be in favor of erring on the side of more general and you can always move to a more specific code later if it turns out it's really needed. But yeah, if there's fierce opinions on both sides, then ¯\(ツ)

Comment threadlib/fs.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ERR_OUT_OF_RANGE is reduced into ERR_VALUE_OUT_OF_RANGE in #17648. So here would be better to use ERR_VALUE_OUT_OF_RANGE.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

yep, was holding off a bit to see if/when #17648 was going to land.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

oh.. right, and the latest updates remove the out of range errors anyway so this is no longer relevant ;-)

@jasnelljasnell mentioned this pull request Dec 14, 2017
2 tasks
Comment threadlib/internal/errors.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would justify this new error a bit more if the error message includes a list of valid symlink types

@jasnell

Copy link
Copy Markdown
MemberAuthor

ping @nodejs/tsc

@jasnell
jasnellforce-pushed the fs-migrate-internal-errors-2 branch from 0e284e1 to c57266dCompareDecember 18, 2017 18:29
@jasnell

Copy link
Copy Markdown
MemberAuthor

Chose to go with @joyeecheung's suggestion of a more specific error message. PTAL

@jasnell
jasnellforce-pushed the fs-migrate-internal-errors-2 branch from 0c2cf69 to a93e157CompareDecember 18, 2017 19:30
@jasnell
jasnell requested a review from a teamDecember 19, 2017 15:34
@joyeecheung

Copy link
Copy Markdown
Member

@jasnell

Copy link
Copy Markdown
MemberAuthor

Thank you @joyeecheung :-) ...

@nodejs/tsc ... need one more TSC sign off please.

@joyeecheung

joyeecheung commented Dec 21, 2017

Copy link
Copy Markdown
Member

Looks like there was something wrong with linux one, new linux one CI: https://ci.nodejs.org/job/node-test-commit-linuxone/11371/

Comment threadlib/fs.js Outdated
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'path',
['string', 'Buffer', 'URL']);
}
if (!Number.isInteger(uid))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we also check for uid >= 0? Same question for the other checks in this commit

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I do believe that uid and gid both can be negative in some edge cases.

Comment threadlib/fs.js Outdated

var req = new FSReqWrap();
if (!Number.isInteger(fd))
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'fd', 'number');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/number/integer/

Comment threadlib/fs.js Outdated
// fs.writeSync(fd, string[, position[, encoding]]);
fs.writeSync = function(fd, buffer, offset, length, position) {
if (!Number.isInteger(fd))
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'fd', 'number');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/number/integer/

Comment threadlib/fs.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

Comment threaddoc/api/errors.md Outdated
[`ERR_INVALID_ARG_TYPE`]: #ERR_INVALID_ARG_TYPE
[`EventEmitter`]: events.html#events_class_eventemitter
[`fs.symlink()`]: fs.html#fs_symlink
[`fs.symlinkSync()`]: fs.html#fs_symlinksymc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: symlinksync

@targos

Copy link
Copy Markdown
Member

General question about Number.isInteger checks: the check passes for values > 2^31-1 in JS land but not in C++ land. Should we guard for this?

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with the nits already noted addresses

@bnoordhuis

Copy link
Copy Markdown
Member

the check passes for values > 2^31-1 in JS land but not in C++ land

Replacing IsInt32() and IsUint32() checks with Number.isInteger() is wrong. Their JS equivalents are x === x | 0 and x === x >>> 0 respectively.

Another issue with Number.isInteger() is that users can monkey-patch it.

@jasnell

Copy link
Copy Markdown
MemberAuthor

Updated to address @bnoordhuis' feedback.

@mcollina and @joyeecheung ... please take another look.

@jasnell

Copy link
Copy Markdown
MemberAuthor

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with the nit above adressed.

Comment threadlib/fs.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment threadsrc/node_file.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IsInt32 (both lines)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FChown is not changed in this PR and also gets Uint32Value(). Are you sure negative uid and gid are possible?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

hmm... they are definitely theoretically possible but you're right. I'll keep these as uint32s

@jasnell
jasnellforce-pushed the fs-migrate-internal-errors-2 branch from 469c61a to 4e75058CompareDecember 22, 2017 17:18
@jasnell

Copy link
Copy Markdown
MemberAuthor

@jasnell
jasnellforce-pushed the fs-migrate-internal-errors-2 branch from 4e75058 to a2d9bd7CompareDecember 22, 2017 20:48
jasnell added a commit that referenced this pull request Dec 22, 2017
PR-URL: #17667
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@jasnell

Copy link
Copy Markdown
MemberAuthor

Landed in 6100e12

@jasnelljasnell closed this Dec 22, 2017

@targostargos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Belated LGTM

@apapirovski

Copy link
Copy Markdown
Contributor

@jasnell it looks like the new assertions in src/node_file.cc are causing some CitGM issues. Would you mind having a look? https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1165/

@joyeecheung

Copy link
Copy Markdown
Member

@apapirovski The CITGM issues are caused by fs.readFile and fs.exists/fs.existsSync raising assertion when the path is undefined. I have a fix coming up.

apapirovski pushed a commit that referenced this pull request Dec 27, 2017
PR-URL: #17852
Refs: #17667
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
apapirovski pushed a commit that referenced this pull request Dec 27, 2017
PR-URL: #17852
Refs: #17667
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

errorsIssues and PRs related to JavaScript errors originated in Node.js core.fsIssues and PRs related to the fs subsystem / file system.semver-majorPRs 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.

8 participants

@jasnell@joyeecheung@targos@bnoordhuis@apapirovski@mcollina@Trott@starkwang