scyph_utils/worker/error.rs
1//! Background worker error types.
2//!
3//! Defines [`WorkerError`] — failures that can occur when joining a background worker task,
4//! typically indicating that the worker task loop panicked.
5
6use scyph_core::AppError;
7
8/// Errors encountered during background worker execution.
9///
10/// ## When Does This Occur?
11///
12/// [`WorkerError::TaskJoin`] is returned by [`super::WorkerHandle::shutdown_and_join`] when the
13/// underlying Tokio task panicked. In normal operation with [`tokio::time::MissedTickBehavior::Skip`] and
14/// proper error handling inside the task closure, this should never occur. If it does, the
15/// error message will contain the panic payload.
16///
17/// Note that panics *inside* individual task iterations are caught and logged (not propagated),
18/// so `TaskJoin` only surfaces if the outer worker loop itself panics.
19///
20/// # Examples
21///
22/// ```rust
23/// use scyph_utils::worker::WorkerError;
24///
25/// let err = WorkerError::TaskJoin("task panicked at 'index out of bounds'".into());
26/// assert!(err.to_string().contains("Worker task error"));
27/// ```
28#[derive(Debug, thiserror::Error)]
29pub enum WorkerError {
30 /// Error joining Tokio background worker task.
31 #[error("Worker task error: {0}")]
32 TaskJoin(String),
33}
34
35impl From<WorkerError> for AppError {
36 fn from(err: WorkerError) -> Self {
37 match err {
38 WorkerError::TaskJoin(msg) => AppError::internal(msg),
39 }
40 }
41}