Exceptions¶
All pyfs-watcher exceptions inherit from FsWatcherError, which itself inherits from Python's built-in Exception. Standard FileNotFoundError and PermissionError are raised for I/O errors.
Hierarchy¶
graph TD
A[Exception] --> B[FsWatcherError]
B --> C[WalkError]
B --> D[HashError]
B --> E[CopyError]
B --> F[WatchError]
B --> G[SearchError]
B --> H[DirDiffError]
B --> I[SyncError]
B --> J[SnapshotError]
B --> K[DiskUsageError]
B --> L[RenameError]
A --> M[FileNotFoundError]
A --> N[PermissionError]
FsWatcherError¶
Base exception for all pyfs-watcher errors. Catch this to handle any library-specific error.
try:
pyfs_watcher.walk_collect("/some/path")
except pyfs_watcher.FsWatcherError as e:
print(f"pyfs-watcher error: {e}")
WalkError¶
Raised when a directory walk operation fails. Typically occurs when the root path cannot be read.
HashError¶
Raised when a file hashing operation fails. This can occur when a file is unreadable or when the thread pool cannot be created for parallel hashing.
CopyError¶
Raised when a copy or move operation fails. Common causes include destination already exists (when overwrite=False), disk full, or permission denied.
WatchError¶
Raised when a file watching operation fails. Typically occurs when the watched path does not exist or the OS watcher cannot be initialized.
SearchError¶
Raised when a content search operation fails. Typically occurs when the root path does not exist or the regex pattern is invalid.
DirDiffError¶
Raised when a directory diff operation fails. Typically occurs when a source or target directory does not exist.
SyncError¶
Raised when a sync operation fails. Typically occurs when the source directory does not exist.
SnapshotError¶
Raised when a snapshot or verify operation fails. This can occur when the path is not a directory, the snapshot JSON is malformed, or the snapshot root no longer exists during verification.
DiskUsageError¶
Raised when a disk usage operation fails. Typically occurs when the path does not exist or is not a directory.
RenameError¶
Raised when a bulk rename operation fails. This can occur when the path is not a directory, the regex pattern is invalid, or an undo is attempted on a dry-run result.
Catching Strategies¶
Catch everything from pyfs-watcher¶
try:
# any pyfs-watcher operation
...
except pyfs_watcher.FsWatcherError as e:
print(f"Library error: {e}")
except (FileNotFoundError, PermissionError) as e:
print(f"I/O error: {e}")