Skip to content

Commit

Permalink
return "file deleted" instead of raising an exception (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Aug 28, 2024
1 parent 4314094 commit 6e3c2c8
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 57 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
rust-version: [stable, '1.63.0']
rust-version: [stable, '1.72']
python-version:
- '3.8'
- '3.9'
Expand All @@ -27,9 +27,9 @@ jobs:
- 'pypy3.9'
- 'pypy3.10'
exclude:
- rust-version: '1.63.0'
- rust-version: '1.72'
os: macos
- rust-version: '1.63.0'
- rust-version: '1.72'
os: windows

runs-on: ${{ matrix.os }}-latest
Expand Down
130 changes: 83 additions & 47 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rust-version = "1.63"

[dependencies]
crossbeam-channel = "0.5.12"
notify = "6.1.1"
notify = {git = "https://github.com/samuelcolvin/notify.git", branch = "keep-io-error"}
pyo3 = { version = "0.22.2", features = ["extension-module", "generate-import-lib"] }

[lib]
Expand Down
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ impl RustNotify {
}
}
Err(e) => {
if debug {
eprintln!("raw-error={:?} error.kind={:?} error.paths={:?}", e, e.kind, e.paths);
}
// see https://github.com/samuelcolvin/watchfiles/issues/282
// if we have IO errors from files not found, we return "file deleted", rather than the error
if let NotifyErrorKind::Io(io_error) = &e.kind {
if io_error.kind() == IOErrorKind::NotFound {
changes_clone.lock().unwrap().extend(
e.paths
.iter()
.map(|p| (CHANGE_DELETED, p.to_string_lossy().to_string())),
);
return;
}
}
*error_clone.lock().unwrap() = Some(format!("error in underlying watcher: {}", e));
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rust_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_does_not_exist(tmp_path: Path):
@skip_unless_linux
def test_does_not_exist_message(tmp_path: Path):
p = tmp_path / 'missing'
with pytest.raises(FileNotFoundError, match='No such file or directory'):
with pytest.raises(FileNotFoundError, match='(No such file or directory|No path was found.)'):
RustNotify([str(p)], False, False, 0, True, False)


Expand Down
Loading

0 comments on commit 6e3c2c8

Please sign in to comment.