2021-08-16 11:49:12 +02:00
|
|
|
//! Watchexec has two error types: for critical and for runtime errors.
|
2018-09-08 13:51:44 +02:00
|
|
|
|
2021-08-16 11:49:12 +02:00
|
|
|
use std::path::PathBuf;
|
2018-09-08 13:51:44 +02:00
|
|
|
|
2021-08-16 11:49:12 +02:00
|
|
|
use miette::Diagnostic;
|
2021-08-16 15:15:17 +02:00
|
|
|
use thiserror::Error;
|
2021-08-18 15:12:50 +02:00
|
|
|
use tokio::{
|
|
|
|
sync::{mpsc, watch},
|
|
|
|
task::JoinError,
|
|
|
|
};
|
2018-09-08 13:51:44 +02:00
|
|
|
|
2021-08-18 15:12:50 +02:00
|
|
|
use crate::{
|
|
|
|
event::Event,
|
|
|
|
fs::{self, Watcher},
|
|
|
|
};
|
2019-01-26 02:45:08 +01:00
|
|
|
|
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),
|
2018-09-08 13:51:44 +02:00
|
|
|
|
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-18 15:12:50 +02:00
|
|
|
|
|
|
|
/// Error received when joining the main watchexec task.
|
|
|
|
#[error("main task join: {0}")]
|
|
|
|
#[diagnostic(code(watchexec::critical::main_task_join))]
|
|
|
|
MainTaskJoin(#[source] JoinError),
|
2018-09-08 13:51:44 +02:00
|
|
|
}
|
|
|
|
|
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),
|
2018-09-08 13:51:44 +02:00
|
|
|
|
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,
|
|
|
|
},
|
2019-01-26 02:45:08 +01:00
|
|
|
|
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-04-30 17:27:17 +02:00
|
|
|
|
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,
|
|
|
|
},
|
2019-02-15 05:02:07 +01:00
|
|
|
|
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,
|
|
|
|
},
|
2018-09-08 13:51:44 +02:00
|
|
|
|
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 {
|
2021-08-17 11:41:13 +02:00
|
|
|
ctx: &'static str,
|
|
|
|
#[source]
|
|
|
|
err: mpsc::error::SendError<Event>,
|
|
|
|
},
|
|
|
|
|
|
|
|
/// 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_try_send))]
|
|
|
|
EventChannelTrySend {
|
2021-08-16 15:15:17 +02:00
|
|
|
ctx: &'static str,
|
|
|
|
#[source]
|
|
|
|
err: mpsc::error::TrySendError<Event>,
|
|
|
|
},
|
2018-09-08 13:51:44 +02:00
|
|
|
}
|
2021-08-18 15:12:50 +02:00
|
|
|
|
|
|
|
/// Errors occurring from reconfigs.
|
|
|
|
#[derive(Debug, Diagnostic, Error)]
|
|
|
|
#[non_exhaustive]
|
|
|
|
pub enum ReconfigError {
|
|
|
|
/// Error received when the fs watcher internal state cannot be updated.
|
|
|
|
#[error("reconfig: fs watch: {0}")]
|
|
|
|
#[diagnostic(code(watchexec::reconfig::fs_watch))]
|
|
|
|
FsWatch(#[from] watch::error::SendError<fs::WorkingData>),
|
|
|
|
}
|