Skip to content

fix(poll): return an error when watching a nonexistent path - #1001

Merged
JohnTitor merged 2 commits into
notify-rs:mainfrom
YuEfSaEDU:fix/pollwatcher-nonexistent-path-error
Sep 19, 2026
Merged

JohnTitor merged 2 commits into
notify-rs:mainfrom
YuEfSaEDU:fix/pollwatcher-nonexistent-path-error

Conversation

@YuEfSaEDU

Copy link
Copy Markdown
Contributor

PollWatcher's watch() returned Ok(()) for paths that cannot be stat-ed because the fs::metadata failure inside WatchData::new was folded into an Option that watch_inner silently ignored, violating the documented Watcher::watch/watch_with contract that nonexistent paths yield an error.

This change threads the error through build_watch_data and watch_inner, mapping it with the existing Error::io_watch helper so io::ErrorKind::NotFound surfaces as ErrorKind::PathNotFound (with the requested path attached) and other io failures as ErrorKind::Io, matching how the inotify and FSEvents backends already behave. Runtime polling semantics are unchanged: an existing watch whose root later disappears is kept and reports scan errors as events.

Adds poll-backend unit tests covering the nonexistent-path error and successful watches of an existing file and directory, plus a changelog entry.

Fixes #998

yuef07 and others added 2 commits September 7, 2026 23:02
PollWatcher::watch returned Ok(()) for a path that could not be
stat-ed: the fs::metadata failure inside WatchData::new was folded
into an Option that watch_inner ignored, so the watch was silently
skipped. Propagate the error through build_watch_data and watch_inner
instead, mapping it with Error::io_watch so a missing path surfaces as
ErrorKind::PathNotFound, matching the other backends.

Fixes notify-rs#998
@JohnTitor
JohnTitor merged commit 1005cb2 into notify-rs:main Sep 19, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: PollWatcher fails silently if path does not exist

3 participants