altair_concurrent/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum Error {
9 #[error("task '{name}' failed: {source}")]
11 TaskFailed {
12 name: &'static str,
14 #[source]
16 source: Box<dyn std::error::Error + Send + Sync>,
17 },
18
19 #[error("execution cancelled")]
21 Cancelled,
22
23 #[error("execution timed out")]
25 Timeout,
26
27 #[error("join error: {0}")]
29 Join(#[from] tokio::task::JoinError),
30}
31
32pub type Result<T> = std::result::Result<T, Error>;
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn task_failed_message_includes_name() {
41 let err = Error::TaskFailed {
42 name: "fetch_user",
43 source: "boom".into(),
44 };
45 assert!(err.to_string().contains("fetch_user"));
46 assert!(err.to_string().contains("boom"));
47 }
48
49 #[test]
50 fn cancelled_renders() {
51 assert_eq!(Error::Cancelled.to_string(), "execution cancelled");
52 }
53
54 #[test]
55 fn timeout_renders() {
56 assert_eq!(Error::Timeout.to_string(), "execution timed out");
57 }
58}