Skip to content

Commit 6e3c2c8

Browse files
authored
return "file deleted" instead of raising an exception (#301)
1 parent 4314094 commit 6e3c2c8

File tree

7 files changed

+118
-57
lines changed

7 files changed

+118
-57
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
os: [ubuntu, macos, windows]
18-
rust-version: [stable, '1.63.0']
18+
rust-version: [stable, '1.72']
1919
python-version:
2020
- '3.8'
2121
- '3.9'
@@ -27,9 +27,9 @@ jobs:
2727
- 'pypy3.9'
2828
- 'pypy3.10'
2929
exclude:
30-
- rust-version: '1.63.0'
30+
- rust-version: '1.72'
3131
os: macos
32-
- rust-version: '1.63.0'
32+
- rust-version: '1.72'
3333
os: windows
3434

3535
runs-on: ${{ matrix.os }}-latest

Cargo.lock

Lines changed: 83 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ rust-version = "1.63"
2525

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

3131
[lib]

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,21 @@ impl RustNotify {
181181
}
182182
}
183183
Err(e) => {
184+
if debug {
185+
eprintln!("raw-error={:?} error.kind={:?} error.paths={:?}", e, e.kind, e.paths);
186+
}
187+
// see https://github.com/samuelcolvin/watchfiles/issues/282
188+
// if we have IO errors from files not found, we return "file deleted", rather than the error
189+
if let NotifyErrorKind::Io(io_error) = &e.kind {
190+
if io_error.kind() == IOErrorKind::NotFound {
191+
changes_clone.lock().unwrap().extend(
192+
e.paths
193+
.iter()
194+
.map(|p| (CHANGE_DELETED, p.to_string_lossy().to_string())),
195+
);
196+
return;
197+
}
198+
}
184199
*error_clone.lock().unwrap() = Some(format!("error in underlying watcher: {}", e));
185200
}
186201
};

tests/test_rust_notify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_does_not_exist(tmp_path: Path):
161161
@skip_unless_linux
162162
def test_does_not_exist_message(tmp_path: Path):
163163
p = tmp_path / 'missing'
164-
with pytest.raises(FileNotFoundError, match='No such file or directory'):
164+
with pytest.raises(FileNotFoundError, match='(No such file or directory|No path was found.)'):
165165
RustNotify([str(p)], False, False, 0, True, False)
166166

167167

0 commit comments

Comments
 (0)