Add context to last runtime io error

and remove generic runtime io error enum variant
This commit is contained in:
Félix Saparelli 2022-01-16 20:00:07 +13:00
parent 2ea62aec6a
commit e2f27a1b01
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
4 changed files with 21 additions and 14 deletions

View File

@ -9,11 +9,11 @@ pub fn init(_args: &ArgMatches<'static>) -> Result<InitConfig> {
let mut config = InitConfig::default();
config.on_error(SyncFnHandler::from(
|data| -> std::result::Result<(), Infallible> {
if let RuntimeError::IoErrorGeneric(_) = data {
// these are often spurious, so condemn them to -v only
error!("{}", data);
return Ok(());
}
// if let RuntimeError::IoError { .. } = data {
// // these are often spurious, so condemn them to -v only
// error!("{}", data);
// return Ok(());
// }
if cfg!(debug_assertions) {
eprintln!("[[{:?}]]", data);

View File

@ -124,14 +124,20 @@ impl Process {
Self::Done(status) => Ok(Some(*status)),
Self::Grouped(c) => {
trace!("waiting on process group");
let status = c.wait().await?;
let status = c.wait().await.map_err(|err| RuntimeError::IoError {
about: "waiting on process group",
err,
})?;
trace!(?status, "converting to ::Done");
*self = Self::Done(status);
Ok(Some(status))
}
Self::Ungrouped(c) => {
trace!("waiting on process");
let status = c.wait().await?;
let status = c.wait().await.map_err(|err| RuntimeError::IoError {
about: "waiting on process (ungrouped)",
err,
})?;
trace!(?status, "converting to ::Done");
*self = Self::Done(status);
Ok(Some(status))

View File

@ -59,12 +59,18 @@ impl Supervisor {
) -> Result<Self, RuntimeError> {
debug!(%grouped, ?command, "spawning command");
let (process, id) = if grouped {
let proc = command.group_spawn()?;
let proc = command.group_spawn().map_err(|err| RuntimeError::IoError {
about: "spawing process group",
err,
})?;
let id = proc.id().ok_or(RuntimeError::ProcessDeadOnArrival)?;
debug!(pgid=%id, "process group spawned");
(Process::Grouped(proc), id)
} else {
let proc = command.spawn()?;
let proc = command.spawn().map_err(|err| RuntimeError::IoError {
about: "spawning process (ungrouped)",
err,
})?;
let id = proc.id().ok_or(RuntimeError::ProcessDeadOnArrival)?;
debug!(pid=%id, "process spawned");
(Process::Ungrouped(proc), id)

View File

@ -25,11 +25,6 @@ pub enum RuntimeError {
#[diagnostic(code(watchexec::runtime::external))]
External(#[from] Box<dyn std::error::Error + Send + Sync>),
/// Generic I/O error, with no additional context.
#[error("io(unspecified): {0}")]
#[diagnostic(code(watchexec::runtime::io_error_generic))]
IoErrorGeneric(#[from] std::io::Error),
/// Generic I/O error, with some context.
#[error("io({about}): {err}")]
#[diagnostic(code(watchexec::runtime::io_error))]