Skip to content

Commit

Permalink
Patch: Better error reporting when a watched path does not exist (#329)
Browse files Browse the repository at this point in the history
Provide a more helpful error message when a watched path does not exist.
For example,

```console
$ ghciwatch --watch does-not-exist
```

**Before**
```
Error:   × Tasks failed:
  │ • run_ghci: ghci event channel closed
  │ • run_watcher: No such file or directory (os error 2)
```

**After**
```
Error:   × Tasks failed:
  │ • run_ghci: ghci event channel closed
  │ • run_watcher: Cannot watch path that doesn't exist: "/home/chris/Projects/tweag/ghciwatch/does-not-exist"
```

Partially resolves #312

- [x] Labeled the PR with `patch`, `minor`, or `major` to request a
version bump when it's merged.
- [ ] Updated the user manual in `docs/`.
- [ ] Added integration / regression tests in `tests/`.

Co-authored-by: Clément Hurlin <[email protected]>
  • Loading branch information
Xophmeister and smelc authored Dec 3, 2024
1 parent cfd9de8 commit b998644
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,18 @@ async fn run_debouncer<T: notify::Watcher>(
for path in &opts.watch {
watcher
.watch(path.as_std_path(), RecursiveMode::Recursive)
.into_diagnostic()?;
.map_err(|err| match err {
notify::Error {
kind: notify::ErrorKind::Io(e),
..
} if e.kind() == std::io::ErrorKind::NotFound => {
miette!(
"Cannot watch path that doesn't exist: {:?}",
path.absolute()
)
}
err => miette!("{err}"),
})?;
}
let mut cache = debouncer.cache();
for path in &opts.watch {
Expand Down

0 comments on commit b998644

Please sign in to comment.