1use std::fmt;
4
5#[derive(Debug)]
7pub enum Error {
8 TaskNotFound { name: String },
10 SpawnFailed { name: String, reason: String },
12 Io(std::io::Error),
14}
15
16impl fmt::Display for Error {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 match self {
19 Self::TaskNotFound { name } => write!(f, "task not found: {name}"),
20 Self::SpawnFailed { name, reason } => {
21 write!(f, "failed to spawn task '{name}': {reason}")
22 }
23 Self::Io(e) => write!(f, "I/O error: {e}"),
24 }
25 }
26}
27
28impl std::error::Error for Error {
29 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
30 match self {
31 Self::Io(e) => Some(e),
32 _ => None,
33 }
34 }
35}
36
37impl From<std::io::Error> for Error {
38 fn from(e: std::io::Error) -> Self {
39 Self::Io(e)
40 }
41}
42
43pub type Result<T> = std::result::Result<T, Error>;