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

fs.watch throws exception when recursive is used in incompatible platform #29947

Closed
wants to merge 15 commits into from

Conversation

exx8
Copy link

@exx8 exx8 commented Oct 12, 2019

This pull request makes fs.watch throw exception whenever it is used in an incompatible platform.
For this change following changes were made to api:

  1. A new error type has been introduced.
  2. fs.watch has been changed accordingly.
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

Solves #29901
This is a breaking change.

@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 Oct 12, 2019
@exx8 exx8 force-pushed the recursive_err branch 2 times, most recently from f39ce99 to 76c5f11 Compare October 12, 2019 19:41
@exx8
Copy link
Author

exx8 commented Oct 12, 2019

Okay I had to alter the first commit so it will be compatible to the format of the project. I believe that the PR is ready now.

doc/api/errors.md Outdated Show resolved Hide resolved
doc/api/fs.md Outdated Show resolved Hide resolved
lib/internal/errors.js Outdated Show resolved Hide resolved
@exx8
Copy link
Author

exx8 commented Oct 13, 2019

The PR has a bit changed, it now uses a new more generic error, ERR_FEATURE_UNAVAILABLE_ON_PLATFORM, which I believe it's more suitable, as like was demonstrated in the conversation with @addaleax , handles more cases (such as fs.chmod, which I hope in the future will also throw this exception for example in windows).

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

Left some comments. Thanks for the PR!

doc/api/fs.md Outdated Show resolved Hide resolved
doc/api/fs.md Outdated Show resolved Hide resolved
lib/internal/errors.js Outdated Show resolved Hide resolved
test/parallel/test-fs-watch-recursive.js Outdated Show resolved Hide resolved
E('ERR_FEATURE_UNAVAILABLE_ON_PLATFORM',
(feature) => 'The feature ' + feature +
' is unavailable on the current platform' +
', which is being used to run Node.js', TypeError);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this could be simplified as:

E('ERR_FEATURE_UNAVAILABLE_ON_PLATFORM',
  'The feature %s is unavailable on the current platform' +
    ', which is being used to run Node.js',
  TypeError);

(It's a semi standard to use that pattern if the error is not too complex)

test/parallel/test-fs-watch-recursive.js Outdated Show resolved Hide resolved
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 the comments incorporated.

@exx8
Copy link
Author

exx8 commented Oct 15, 2019

I switched from try and catch to built in function & extracted the old logic so it will be more neat. I also reformatted the errors.

@BridgeAR
Copy link
Member

Still LGTM

@Trott Trott added the semver-major PRs that contain breaking changes and should be released in the next major version. label Oct 16, 2019
@Trott
Copy link
Member

Trott commented Oct 16, 2019

@nodejs/tsc

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -2352,6 +2352,12 @@ The `--entry-type=...` flag is not compatible with the Node.js REPL.
Used when an [ES Module][] loader hook specifies `format: 'dynamic'` but does
not provide a `dynamicInstantiate` hook.

<a id="ERR_FEATURE_UNAVAILABLE_ON_PLATFORM"></a>
#### ERR_FEATURE_UNAVAILABLE_ON_PLATFORM
Copy link
Member

Choose a reason for hiding this comment

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

Just a nit... I would just make this more generic like ERR_NOT_IMPLEMENTED or ERR_NOT_AVAILABLE, but it's not critical

Copy link
Author

Choose a reason for hiding this comment

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

I think there is a great value of knowing this error occurs only on one platform, and that it isn't something that node.js itself doesn't support.

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Oct 17, 2019
@nodejs-github-bot
Copy link
Collaborator

@exx8
Copy link
Author

exx8 commented Oct 18, 2019

ok I can see that some tests fail. Can I contribute to fix it?

@nodejs-github-bot
Copy link
Collaborator

@addaleax
Copy link
Member

addaleax commented Nov 5, 2019

@exx8 Sorry, it’s been a while and the old CI results are no longer available. I’ve started a new one, though.

Generally, feel free to ping us if you feel like a PR is stalling out somehow.

@exx8
Copy link
Author

exx8 commented Nov 6, 2019

@exx8 Sorry, it’s been a while and the old CI results are no longer available. I’ve started a new one, though.

Generally, feel free to ping us if you feel like a PR is stalling out somehow.

It seems that there is a merge conflict now (according to the build:

18:37:55 M	lib/internal/errors.js
18:37:55 Falling back to patching base and 3-way merge...
18:37:55 Auto-merging lib/internal/errors.js
18:37:55 CONFLICT (content): Merge conflict in lib/internal/errors.js
18:37:55 error: Failed to merge in the changes.

) or it might be a false alarm (as github says there aren't).
Do you want me to fix it?
Will it require everyone to re-approve the PR?
@addaleax

@addaleax
Copy link
Member

addaleax commented Nov 6, 2019

) or it might be a false alarm (as github says there aren't).

I think the issue is that one of the 14 commits in this PR has a merge conflict, but not the PR as a whole (i.e. one of the later commits removed the merge conflict again).

Do you want me to fix it?

It would be helpful if you could rebase this (not git merge) against master, so that we can run CI the usual way. If you’re not feeling comfortable with that, you can also let somebody else do that.

Will it require everyone to re-approve the PR?

If the contents of the PR stay the same apart from resolving merge conflicts, that should be okay.

Eran Levin and others added 6 commits January 24, 2020 05:56
Co-Authored-By: Ben Noordhuis <info@bnoordhuis.nl>
Co-Authored-By: Ben Noordhuis <info@bnoordhuis.nl>
Co-Authored-By: Ben Noordhuis <info@bnoordhuis.nl>
@Trott
Copy link
Member

Trott commented Jan 24, 2020

Rebased to eliminate conflict.

@nodejs-github-bot

This comment has been minimized.

@Trott Trott added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 24, 2020
@BridgeAR
Copy link
Member

@Trott seems like there's a linter issue now?

doc/api/errors.md Outdated Show resolved Hide resolved
@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Jan 24, 2020

@nodejs-github-bot
Copy link
Collaborator

Trott pushed a commit that referenced this pull request Jan 25, 2020
This pull request makes fs.watch throw exception,
whenever it is used in an incompatible platform.
For this change following changes were made to api:

1.a new error type has been introduced.
2.fs.watch has been changed accordingly.

Users who use recursive  on
non-windows and osx platforms,
will face a new exception.
For this reason, it's a breaking change.

Fixes: #29901

PR-URL: #29947
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@Trott
Copy link
Member

Trott commented Jan 25, 2020

Landed in 67e067e.

Thanks for the contribution! 🎉

@Trott Trott closed this Jan 25, 2020
@Trott Trott added the notable-change PRs with changes that should be highlighted in changelogs. label Jan 25, 2020
MylesBorins pushed a commit that referenced this pull request Jan 30, 2020
This makes sure this function stays backwards compatible in case
it's accessed through the binding directly.

Refs: #29947 (comment)

Backport-PR-URL: #31431
PR-URL: #30858
Refs: #30767
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
BethGriggs pushed a commit that referenced this pull request Feb 6, 2020
This makes sure this function stays backwards compatible in case
it's accessed through the binding directly.

Refs: #29947 (comment)

Backport-PR-URL: #31431
PR-URL: #30858
Refs: #30767
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
molant added a commit to molant/cli that referenced this pull request Feb 19, 2020
Use `chokidar` to track file system changes as soon it will throw an
error if the platform does not support `{ recursive: true }`.

Fix also an error where the built file was not being deleted when the
source was removed.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Fix react-native-community#989
Ref: nodejs/node#29947
molant added a commit to molant/cli that referenced this pull request Feb 19, 2020
Use `chokidar` to track file system changes as soon it will throw an
error if the platform does not support `{ recursive: true }`.

Fix also an error where the built file was not being deleted when the
source was removed.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Fix react-native-community#989
Ref: nodejs/node#29947
thymikee pushed a commit to react-native-community/cli that referenced this pull request Feb 20, 2020
Use `chokidar` to track file system changes as soon it will throw an
error if the platform does not support `{ recursive: true }`.

Fix also an error where the built file was not being deleted when the
source was removed.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Fix #989
Ref: nodejs/node#29947
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. errors Issues and PRs related to JavaScript errors originated in Node.js core. fs Issues and PRs related to the fs subsystem / file system. notable-change PRs with changes that should be highlighted in changelogs. 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.