Skip to content

Commit

Permalink
Don't spam warnings on expected exceptions (#82)
Browse files Browse the repository at this point in the history
* Don't spam warnings on expected exceptions

* Put try/except in the right place
  • Loading branch information
pbiggar committed Mar 12, 2022
1 parent 5c244a2 commit c9a4622
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions watchgod/watcher.py
Expand Up @@ -56,19 +56,29 @@ def _walk_dir(self, dir_path: str, changes: Set['FileChange'], new_files: Dict[s
if self.ignored_paths is not None and os.path.join(dir_path, entry) in self.ignored_paths:
continue

if entry.is_dir():
if self.should_watch_dir(entry):
self._walk_dir(entry.path, changes, new_files)
elif self.should_watch_file(entry):
self._watch_file(entry.path, changes, new_files, entry.stat())
try:
if entry.is_dir():
if self.should_watch_dir(entry):
self._walk_dir(entry.path, changes, new_files)
elif self.should_watch_file(entry):
self._watch_file(entry.path, changes, new_files, entry.stat())
except FileNotFoundError as e:
# sometimes we can't find the file. If it was deleted since
# `entry` was allocated, then it doesn't matter and can be
# ignored. It might also be a bad symlink, in which case we
# should silently skip it - users don't want to constantly spam
# warnings, esp if they can't remove the symlink (eg from a
# node_modules directory).
pass


def check(self) -> Set['FileChange']:
changes: Set['FileChange'] = set()
new_files: Dict[str, float] = {}
try:
self._walk(self.root_path, changes, new_files)
except OSError as e:
# happens when a directory has been deleted between checks
# check for unexpected errors
logger.warning('error walking file system: %s %s', e.__class__.__name__, e)

# look for deleted
Expand Down

0 comments on commit c9a4622

Please sign in to comment.