1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use std::fmt;
use std::sync::PoisonError;
/// Unified error type for the library.
#[derive(Debug)]
pub enum BeaverError {
/// Required field is missing when building a task.
BuilderMissingField(&'static str),
/// Queue is full, cannot enqueue.
QueueFull,
/// Execution thread has been released, cannot enqueue.
DamReleased,
/// Internal lock was poisoned (usually caused by a panic).
LockPoisoned,
/// No execution thread available.
NoDam,
/// Range interval task: number of interval ranges exceeds total retry count.
RangeIntervalRangesExceedTotal { total: u32, ranges_count: usize },
}
impl fmt::Display for BeaverError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BeaverError::BuilderMissingField(field) => {
write!(f, "builder missing required field: {}", field)
}
BeaverError::QueueFull => write!(f, "task queue is full"),
BeaverError::DamReleased => write!(f, "execution thread has been released"),
BeaverError::LockPoisoned => write!(f, "internal lock poisoned"),
BeaverError::NoDam => write!(f, "no execution thread available"),
BeaverError::RangeIntervalRangesExceedTotal {
total,
ranges_count,
} => {
write!(
f,
"range interval ranges count ({}) exceeds total retry count ({})",
ranges_count, total
)
}
}
}
}
impl std::error::Error for BeaverError {}
impl<T> From<PoisonError<T>> for BeaverError {
fn from(_: PoisonError<T>) -> Self {
BeaverError::LockPoisoned
}
}
/// Unified Result type for the library.
pub type BeaverResult<T> = Result<T, BeaverError>;
/// Runtime error, passed to the caller via Listener.
#[derive(Debug, Clone)]
pub enum RuntimeError {
/// Internal lock was poisoned.
LockPoisoned,
/// An error occurred during task execution (e.g. panic in work, reported with message).
TaskExecutionFailed(String),
/// A bounded retry task (fixed-count / time-interval / range-interval) ran
/// every permitted attempt and the last one still returned
/// [`WorkResult::NeedRetry`](crate::WorkResult::NeedRetry) — i.e. it never
/// succeeded. Reported via [`WorkListener::on_error`](crate::WorkListener::on_error)
/// so that "retries exhausted without success" is distinct from the
/// successful-completion signal [`WorkListener::on_complete`](crate::WorkListener::on_complete).
/// Periodic tasks never produce this (they have no retry budget to exhaust).
RetriesExhausted,
}
impl fmt::Display for RuntimeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RuntimeError::LockPoisoned => write!(f, "internal lock poisoned during execution"),
RuntimeError::TaskExecutionFailed(msg) => write!(f, "task execution failed: {}", msg),
RuntimeError::RetriesExhausted => {
write!(f, "task retries exhausted without success")
}
}
}
}
impl std::error::Error for RuntimeError {}