-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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: migrate fs_event_wrap to internal/errors #17851
Conversation
ping @TimothyGu |
@maclover7 #17682 landed. Can you please rebase? |
66bb103
to
c28b53a
Compare
updated @targos |
test/parallel/test-fs-watch.js
Outdated
@@ -64,7 +64,7 @@ for (const testCase of cases) { | |||
assert.strictEqual(eventType, 'change'); | |||
assert.strictEqual(argFilename, testCase.fileName); | |||
|
|||
watcher.start(); // should not crash | |||
watcher.start('should not crash'); // should not crash |
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.
this is not the same, why this change?
It seems we are not exposing start
at all, see https://nodejs.org/api/fs.html#fs_class_fs_fswatcher.
I think we should add it to the docs.
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.
Looks like this should be watcher.start(testCase[testCase.field])
?
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.
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.
Umm, looking more closely I think .start()
is accepted the second time it is called (i.e. the wrap is already initialized to watch on a file), so in JS land we should check if the wrap is initialized before calling validatePath()
. The easiest way to do it is to store a field in the FSWatcher.prototype.start()
in JS land, echoing what's being done in the C++ land (it also needs to be updated in .close()
)
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.
Or, if we don't want to return silently when someone tries to call .start()
again on the initialized watcher:
if (!isInitialized) {
validatePath(filename);
} else {
throw errors.Error('ERR_FS_EVENT_STARTED'); // A new Error indicating this has been started.
}
If we don't even want to document .start()
, we can just assert(isInitialized)
instead of creating a public error for it.
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.
LGTM once comment about watcher.start() is addressed.
3716c57
to
067a544
Compare
updated @joyeecheung PTAL |
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.
LGTM with an suggestion
@@ -1664,6 +1664,8 @@ fs.appendFileSync = function(path, data, options) { | |||
function FSWatcher() { | |||
EventEmitter.call(this); | |||
|
|||
this._initialized = false; |
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 you add a comment here mentioning that this should be kept in sync with the initialized
field of the C++ wrap? (Arguably better if this is an accessor property on the prototype of FSWatcher
, that way there is no need to set this field in start
and close
, although that brings a few more calls into C++ so I am fine with this as well)
@maclover7 would you be so kind and rebase and also address the comment? |
Ping @maclover7 |
Closing due to no further progress. @maclover7 please feel free to reopen in case you would like to continue working on this. |
Migrates
fs_event_wrap.cc
to internal/errors style.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
fs