GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs.watchFile fixes by brendanashworth · Pull Request #2093 · nodejs/node

Conversation

@brendanashworth

@brendanashworth brendanashworth commented Jul 2, 2015

Copy link
Copy Markdown
Contributor

There were some issues with fs.watchFile:

  • no tests
  • bad argument check on non-function but truthy listener
  • no doc comment about change in functionality since v0.10

This fixes them. Supersedes #2028, fixes #1745.
/cc @thefourtheye @bnoordhuis @evanlucas

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@brendanashworth brendanashworth added fs Issues and PRs related to file-system APIs and the fs module. doc Issues and PRs related to Node.js documentation. labels Jul 2, 2015
@brendanashworth brendanashworth mentioned this pull request Jul 2, 2015
fs: fix StatWatcher to handle error codes #2028
Closed
thefourtheye
thefourtheye reviewed Jul 2, 2015
View reviewed changes
Comment thread test/parallel/test-fs-watchfile.js Outdated

@thefourtheye thefourtheye Jul 2, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Wouldn't it be better if we had the condition to check if the callback is really for ENOENT, as suggested here #2028 (comment)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@brendanashworth brendanashworth Jul 2, 2015

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'd think it'd be better too, but I'm not sure how to ensure it is ENOENT. Is checking curr.ino > 0 the only way/right way?

edit: cause I don't know what ino stands for :/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thefourtheye thefourtheye Jul 2, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@brendanashworth I think it is inode number. cc @bnoordhuis

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bnoordhuis bnoordhuis Jul 10, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yes, it's the inode number. curr.ino > 0 is just an example, though; on error, all the fields will be zero. It would be good to document that behavior in the fs.watchFile() documentation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thefourtheye thefourtheye Jul 10, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@bnoordhuis I was thinking, once this lands, I ll include the checks for non-existent file in fs.Stats section and mention that in fs.watchFile section. That should be fine, right?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bnoordhuis bnoordhuis Jul 10, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I don't think fs.Stats is the right place for that, it's specific to fs.watchFile().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thefourtheye

thefourtheye commented Jul 2, 2015

Copy link
Copy Markdown
Contributor

Had only minor comments. It can land as-is, I guess.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kanongil

kanongil commented Jul 2, 2015

Copy link
Copy Markdown
Contributor

Why would you change the behavior on non-existant files? It doesn't make much sense if the callback is triggered immediately, without any actual changes, as I reported in #1745.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Jul 2, 2015

Copy link
Copy Markdown
Member

@kanongil See this comment. Executive summary: no callback means you can't distinguish between no file and no events.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kanongil

kanongil commented Jul 2, 2015

Copy link
Copy Markdown
Contributor

@bnoordhuis Ah, I see. I guess this makes sense.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth
fs: fix error on bad listener type
14354a0
When the listener was truthy but NOT a function, fs.watchFile would
throw an error through the EventEmitter. This caused a problem because
it would only be thrown after the listener was started, which left the
listener on.

There should be no backwards compatability issues because the error was
always thrown, just in a different manner.

Also adds tests for this and other basic functionality.
@brendanashworth
brendanashworth force-pushed the new/fs-watchfile-tests branch from 4d5655d to d9c795e Compare July 2, 2015 19:02
@brendanashworth

brendanashworth commented Jul 2, 2015

Copy link
Copy Markdown
Contributor Author

Pushed up fixed commits, PTAL @thefourtheye @bnoordhuis.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

thefourtheye
thefourtheye reviewed Jul 2, 2015
View reviewed changes
Comment thread test/parallel/test-fs-watchfile.js Outdated

@thefourtheye thefourtheye Jul 2, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I am not sure if unwatching here is a good idea. If some change triggers the callback more than once, even in the ENOENT case, then this testcase will miss that, as it is unwatching immediately in the first invocation itself. @bnoordhuis What do you think?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bnoordhuis bnoordhuis Jul 2, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

What's the alternative?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thefourtheye thefourtheye Jul 2, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I am not sure if it will work fine but how about unwatching at the process's exit event?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@brendanashworth brendanashworth Jul 2, 2015

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It won't exit without unwatching, as the watcher will keep the process open.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thefourtheye thefourtheye Jul 2, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Oh, then I am out of ideas. We can leave it as it is I guess. Thanks for clarifying @brendanashworth :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thefourtheye thefourtheye Jul 4, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@trevnorris Can you please explain the making it not persistent part? Actually the original PR had a setTimeout of 2ms and unwatch was called from there. You meant something like that?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@trevnorris trevnorris Jul 4, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Reference documentation: https://iojs.org/api/fs.html#fs_fs_watchfile_filename_options_listener

persistent indicates whether the process should continue to run as long as files are being watched

I'm assuming that a file that doesn't exist can't be watched. Thus allowing the process to shutdown.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bnoordhuis bnoordhuis Jul 4, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I don't think that would work. { persistent: false } unrefs the handle immediately. io.js would quit as soon as the script finished, before the callback has a chance to run.

FWIW, the test looks fine to me.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@trevnorris trevnorris Jul 4, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That's what I was wondering.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@brendanashworth brendanashworth Jul 4, 2015

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

When I had a timer in, the test was admittedly very flaky (10-20% failure rate).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bnoordhuis

bnoordhuis commented Jul 2, 2015

Copy link
Copy Markdown
Member

LGTM FWIW.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth

brendanashworth commented Jul 3, 2015

Copy link
Copy Markdown
Contributor Author

@thefourtheye LGTY?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Jul 3, 2015

Copy link
Copy Markdown
Contributor

@brendanashworth I was okay with the initial version itself ;-) LGTM.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth

brendanashworth commented Jul 3, 2015

Copy link
Copy Markdown
Contributor Author

CI: https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/92/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Jul 4, 2015

Copy link
Copy Markdown
Member

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye thefourtheye mentioned this pull request Jul 5, 2015
path: Throwing error on zero length strings #2105
Closed
thefourtheye
thefourtheye reviewed Jul 6, 2015
View reviewed changes
Comment thread test/parallel/test-fs-watchfile.js Outdated

@thefourtheye thefourtheye Jul 6, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can we simply use common.mustCall here and get rid of the counter?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@brendanashworth brendanashworth Jul 6, 2015

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I had the counter in so that if the callback were fired more than once, it would error. I'm not sure if that is still possible unless it is called synchronously twice - but just in case, I'd like to err on the side of keeping the counter.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bnoordhuis bnoordhuis Jul 6, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

common.mustCall() checks the call count at exit. You don't strictly need a counter here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@brendanashworth brendanashworth Jul 6, 2015

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I will change this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cjihrig cjihrig mentioned this pull request Jul 6, 2015
fs: Fix StatWatcher to handle error codes passed in status nodejs/node-v0.x-archive#25469
Closed
@brendanashworth

brendanashworth commented Jul 6, 2015

Copy link
Copy Markdown
Contributor Author

I plan on merging tonight.

edit: nope nevermind

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth
doc: document fs.watchFile behaviour on ENOENT
f6467b0
When fs.watchFile encounters an ENOENT error, it invokes the given
callback with some error data. This caused an issue as it was different
behaviour than Node v0.10. Instead of changing this behaviour, document
it and add a test.

Ref: nodejs#1745
Ref: nodejs#2028
@brendanashworth
brendanashworth force-pushed the new/fs-watchfile-tests branch from d9c795e to f6467b0 Compare July 10, 2015 08:53
@brendanashworth

brendanashworth commented Jul 10, 2015

Copy link
Copy Markdown
Contributor Author

Force pushed with common.mustCall, ptal @bnoordhuis @thefourtheye .

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

thefourtheye
thefourtheye reviewed Jul 10, 2015
View reviewed changes
Comment thread test/parallel/test-fs-watchfile.js

@thefourtheye thefourtheye Jul 10, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Oh, we are not doing inode check to confirm to see if the file really doesn't exist. Meh. Its okay I guess. LGTM 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bnoordhuis

bnoordhuis commented Jul 10, 2015

Copy link
Copy Markdown
Member

One more LGTM, with a documentation suggestion. Can you run the CI before landing?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth

brendanashworth commented Jul 10, 2015

Copy link
Copy Markdown
Contributor Author

CI is happy: https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/141/.

@thefourtheye would you like to submit a follow up PR with the doc addition? I don't know enough to make a good writeup.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Jul 10, 2015

Copy link
Copy Markdown
Contributor

@brendanashworth I think its high time you landed this ;-) We can discuss on this thread about the documentation even after that :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

brendanashworth added a commit that referenced this pull request Jul 10, 2015
@brendanashworth
fs: fix error on bad listener type
1afc0c9
When the listener was truthy but NOT a function, fs.watchFile would
throw an error through the EventEmitter. This caused a problem because
it would only be thrown after the listener was started, which left the
listener on.

There should be no backwards compatability issues because the error was
always thrown, just in a different manner.

Also adds tests for this and other basic functionality.

PR-URL: #2093
Reviewed-By: Ben Noordhuis <[email protected]>
brendanashworth added a commit that referenced this pull request Jul 10, 2015
@brendanashworth
doc: document fs.watchFile behaviour on ENOENT
23efb05
When fs.watchFile encounters an ENOENT error, it invokes the given
callback with some error data. This caused an issue as it was different
behaviour than Node v0.10. Instead of changing this behaviour, document
it and add a test.

Ref: #1745
Ref: #2028
Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: #2093
@brendanashworth

brendanashworth commented Jul 10, 2015

Copy link
Copy Markdown
Contributor Author

Thank you reviewers, sorry for the lag. Merged in 12bc397...23efb05.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth brendanashworth closed this Jul 10, 2015
@thefourtheye

thefourtheye commented Jul 10, 2015

Copy link
Copy Markdown
Contributor

@brendanashworth Awesome :-) Thanks :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye thefourtheye mentioned this pull request Jul 12, 2015
doc: note about non-existent files in watchFile #2169
Closed
@Fishrock123 Fishrock123 mentioned this pull request Jul 16, 2015
Release Proposal: v2.4.0 #2189
Merged
@maboiteaspam maboiteaspam mentioned this pull request Jul 16, 2015
fix #19 nodejs/changelog-maker#20
Merged
@thefourtheye thefourtheye mentioned this pull request Jul 19, 2015
fs.watchFile calling listener on non-existing files #1745
Closed
ronkorving
ronkorving reviewed Jul 23, 2015
View reviewed changes
Comment thread lib/fs.js

@ronkorving ronkorving Jul 23, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

A bit late, since already merged, but shouldn't this be a TypeError?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@brendanashworth brendanashworth Jul 23, 2015

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Never too late :) you're right though, if you wanted to submit a PR I'd review it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
thefourtheye added a commit to thefourtheye/io.js that referenced this pull request Aug 4, 2015
@thefourtheye
doc,test: note and test about non-existent files, in watchFile
ce7402d
As per the discussion in
nodejs#2093 (comment), this
patch improves the Note section in watchFile to clarify about the
non-existent files.

This patch also includes a test which checks if a file not present, the
callback is invoked at least once and if the file is created after
the callback is invoked, it will be invoked again with new stat
objects.

PR-URL: nodejs#2169
thefourtheye added a commit that referenced this pull request Aug 4, 2015
@thefourtheye
doc,test: documents behaviour of non-existent file
ed85c95
As per the discussion in
#2093 (comment), this
patch documents the behavior of calling fs.watchFile() with a path that
does not yet exist.

This patch also includes a test which checks if a file not present, the
callback is invoked at least once and if the file is created after
the callback is invoked, it will be invoked again with new stat
objects.

PR-URL: #2169
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Brendan Ashworth <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

doc Issues and PRs related to Node.js documentation. fs Issues and PRs related to file-system APIs and the fs module.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

fs.watchFile calling listener on non-existing files

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@brendanashworth @thefourtheye @kanongil @bnoordhuis @trevnorris @ronkorving @evanlucas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.