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

src: prefer param function check over args length #23835

Closed
wants to merge 1 commit into from
Closed

src: prefer param function check over args length #23835

wants to merge 1 commit into from

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Oct 23, 2018

We have to override some fs methods in Electron, and as I looked at their original impls I believe that checking the type of the second argument as opposed to simply the number of arguments passed is more consistent and reliable.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Oct 23, 2018
lib/fs.js Outdated Show resolved Hide resolved
@refack
Copy link
Contributor

refack commented Oct 23, 2018

👍

I had a thought once about doing something like:

function fstat(fd, ...args) {
  const lastArg = args.pop();
  const callback = (typeof lastArg === 'function') ? lastArg : throw ..;
  const options = args.pop() || {};
  ...
}

Actually what we need is a generic arg validator :dream:

function fstat(...args) {
  const { fd, options, callback } = validateArgs(args, { some sort of contract });

@mscdex
Copy link
Contributor

mscdex commented Oct 23, 2018

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

lib/fs.js Outdated
@@ -412,7 +412,7 @@ function open(path, flags, mode, callback) {
path = toPathIfFileURL(path);
validatePath(path);
const flagsNumber = stringToFlags(flags);
if (arguments.length < 4) {
if (typeof mode === 'function') {
Copy link
Member

Choose a reason for hiding this comment

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

I think this will conflict with @bnoordhuis's work on #23767

Copy link
Member

Choose a reason for hiding this comment

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

Should we land #23767 first and then adapt this PR to that change? Seems do-able. /cc @codebytere @bnoordhuis

@Trott
Copy link
Member

Trott commented Nov 6, 2018

@codebytere This seems ready to go if we can get a rebase to resolve the merge conflict with #23767...

@codebytere
Copy link
Member Author

@Trott i'll handle first thing tomorrow!

@codebytere
Copy link
Member Author

codebytere commented Nov 6, 2018

@Trott should be set! i couldn't change this line becuase if i simply checked for flags being a function that didn't properly account for the error case where no callback was passed (i.e. only one arg passed) and would improperly fail tests with ERR_INVALID_OPT_VALUE instead of ERR_INVALID_CALLBACK.

@refack
Copy link
Contributor

refack commented Nov 6, 2018

@refack refack added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Nov 6, 2018
@Trott
Copy link
Member

Trott commented Nov 8, 2018

Landed in 7cf5679

@Trott Trott closed this Nov 8, 2018
Trott pushed a commit to Trott/io.js that referenced this pull request Nov 8, 2018
PR-URL: nodejs#23835
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
BridgeAR pushed a commit that referenced this pull request Nov 14, 2018
PR-URL: #23835
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
kiyomizumia pushed a commit to kiyomizumia/node that referenced this pull request Nov 15, 2018
PR-URL: nodejs#23835
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
codebytere added a commit that referenced this pull request Nov 29, 2018
PR-URL: #23835
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
MylesBorins pushed a commit that referenced this pull request Nov 29, 2018
PR-URL: #23835
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
@codebytere codebytere mentioned this pull request Nov 29, 2018
MylesBorins pushed a commit that referenced this pull request Dec 3, 2018
PR-URL: #23835
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.