Split known create errors to get proper help text

This commit is contained in:
Félix Saparelli 2022-02-12 19:49:02 +13:00
parent 3b64a41d80
commit b77da446d8
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
2 changed files with 38 additions and 17 deletions

View File

@ -133,20 +133,38 @@ impl From<TaggedFiltererError> for RuntimeError {
#[diagnostic(url(docsrs))]
pub enum FsWatcherError {
/// Error received when creating a filesystem watcher fails.
///
/// Also see `TooManyWatches` and `TooManyHandles`.
#[error("failed to instantiate")]
#[diagnostic(
code(watchexec::fs_watcher::create),
help("perhaps retry with the poll watcher")
)]
Create {
/// The underlying error.
#[source]
err: notify::Error,
Create(#[source] notify::Error),
/// A hint to the user about resolving the error.
#[source_code]
help: String,
},
/// Error received when creating or updating a filesystem watcher fails because there are too many watches.
///
/// This is the OS error 28 on Linux.
#[error("failed to instantiate: too many watches")]
#[diagnostic(code(watchexec::fs_watcher::too_many_watches))]
#[cfg_attr(target_os = "linux", diagnostic(help("you will want to increase your inotify.max_user_watches, see inotify(7) and https://watchexec.github.io/docs/inotify-limits.html")))]
#[cfg_attr(
not(target_os = "linux"),
diagnostic(help("this should not happen on your platform"))
)]
TooManyWatches(#[source] notify::Error),
/// Error received when creating or updating a filesystem watcher fails because there are too many file handles open.
///
/// This is the OS error 24 on Linux. It may also occur when the limit for inotify instances is reached.
#[error("failed to instantiate: too many handles")]
#[diagnostic(code(watchexec::fs_watcher::too_many_handles))]
#[cfg_attr(target_os = "linux", diagnostic(help("you will want to increase your `nofile` limit, see pam_limits(8); or increase your inotify.max_user_instances, see inotify(7) and https://watchexec.github.io/docs/inotify-limits.html")))]
#[cfg_attr(
not(target_os = "linux"),
diagnostic(help("this should not happen on your platform"))
)]
TooManyHandles(#[source] notify::Error),
/// Error received when reading a filesystem event fails.
#[error("received an event that we could not read")]

View File

@ -53,16 +53,19 @@ impl Watcher {
}
.map_err(|err| RuntimeError::FsWatcher {
kind: self,
err: FsWatcherError::Create {
help: if cfg!(target_os = "linux") && (matches!(err.kind, notify::ErrorKind::MaxFilesWatch) || matches!(err.kind, notify::ErrorKind::Io(ref ioerr) if ioerr.raw_os_error() == Some(28))) {
"you will want to increase your inotify.max_user_watches, see inotify(7) and https://watchexec.github.io/docs/inotify-limits.html"
} else if cfg!(target_os = "linux") && matches!(err.kind, notify::ErrorKind::Io(ref ioerr) if ioerr.raw_os_error() == Some(24)) {
"you will want to increase your `nofile` limit, see pam_limits(8)"
err: if cfg!(target_os = "linux")
&& (matches!(err.kind, notify::ErrorKind::MaxFilesWatch)
|| matches!(err.kind, notify::ErrorKind::Io(ref ioerr) if ioerr.raw_os_error() == Some(28)))
{
FsWatcherError::TooManyWatches(err)
} else if cfg!(target_os = "linux")
&& matches!(err.kind, notify::ErrorKind::Io(ref ioerr) if ioerr.raw_os_error() == Some(24))
{
FsWatcherError::TooManyHandles(err)
} else {
"you may want to try again with the polling watcher"
}.into(),
err,
}})
FsWatcherError::Create(err)
},
})
}
}