watchexec/lib/src/error.rs

86 lines
2.6 KiB
Rust
Raw Normal View History

2021-08-16 11:49:12 +02:00
//! Watchexec has two error types: for critical and for runtime errors.
2021-08-16 11:49:12 +02:00
use std::path::PathBuf;
2021-08-16 11:49:12 +02:00
use miette::Diagnostic;
2021-08-16 15:15:17 +02:00
use thiserror::Error;
2021-08-16 11:49:12 +02:00
use tokio::sync::mpsc;
2021-08-16 11:49:12 +02:00
use crate::{event::Event, fs::Watcher};
2021-08-16 11:49:12 +02:00
/// Errors which are not recoverable and stop watchexec execution.
#[derive(Debug, Diagnostic, Error)]
#[non_exhaustive]
pub enum CriticalError {
/// A critical I/O error occurred.
#[error(transparent)]
#[diagnostic(code(watchexec::critical::io_error))]
IoError(#[from] std::io::Error),
2021-08-16 11:49:12 +02:00
/// Error received when an event cannot be sent to the errors channel.
#[error("cannot send internal runtime error: {0}")]
#[diagnostic(code(watchexec::critical::error_channel_send))]
ErrorChannelSend(#[from] mpsc::error::SendError<RuntimeError>),
}
2021-08-16 11:49:12 +02:00
/// Errors which _may_ be recoverable, transient, or only affect a part of the operation, and should
/// be reported to the user and/or acted upon programatically, but will not outright stop watchexec.
#[derive(Debug, Diagnostic, Error)]
#[non_exhaustive]
pub enum RuntimeError {
/// Generic I/O error, with no additional context.
#[error(transparent)]
#[diagnostic(code(watchexec::runtime::io_error))]
IoError(#[from] std::io::Error),
2021-08-16 11:49:12 +02:00
/// Error received when creating a filesystem watcher fails.
#[error("{kind:?} watcher failed to instantiate: {err}")]
#[diagnostic(
code(watchexec::runtime::fs_watcher_error),
2021-08-16 15:15:17 +02:00
help("perhaps retry with the poll watcher")
2021-08-16 11:49:12 +02:00
)]
2021-08-16 15:15:17 +02:00
FsWatcherCreate {
kind: Watcher,
#[source]
err: notify::Error,
},
2021-08-16 11:49:12 +02:00
/// Error received when reading a filesystem event fails.
#[error("{kind:?} watcher received an event that we could not read: {err}")]
2021-08-16 15:15:17 +02:00
#[diagnostic(code(watchexec::runtime::fs_watcher_event))]
FsWatcherEvent {
kind: Watcher,
#[source]
err: notify::Error,
},
2021-08-16 11:49:12 +02:00
/// Error received when adding to the pathset for the filesystem watcher fails.
#[error("while adding {path:?} to the {kind:?} watcher: {err}")]
2021-08-16 15:15:17 +02:00
#[diagnostic(code(watchexec::runtime::fs_watcher_path_add))]
FsWatcherPathAdd {
path: PathBuf,
kind: Watcher,
#[source]
err: notify::Error,
},
2021-08-16 11:49:12 +02:00
/// Error received when removing from the pathset for the filesystem watcher fails.
#[error("while removing {path:?} from the {kind:?} watcher: {err}")]
2021-08-16 15:15:17 +02:00
#[diagnostic(code(watchexec::runtime::fs_watcher_path_remove))]
FsWatcherPathRemove {
path: PathBuf,
kind: Watcher,
#[source]
err: notify::Error,
},
2021-08-16 11:49:12 +02:00
/// Error received when an event cannot be sent to the event channel.
#[error("cannot send event from {ctx}: {err}")]
#[diagnostic(code(watchexec::runtime::event_channel_send))]
2021-08-16 15:15:17 +02:00
EventChannelSend {
ctx: &'static str,
#[source]
err: mpsc::error::TrySendError<Event>,
},
}