Skip to main content

ttrackr/db/
utils.rs

1use std::fmt::{Display, Formatter, Result};
2
3#[derive(Debug, Clone)]
4pub struct TaskNotFound;
5
6impl Display for TaskNotFound {
7    fn fmt(&self, f: &mut Formatter) -> Result {
8        write!(f, "Task not found")
9    }
10}
11
12impl std::error::Error for TaskNotFound {
13    fn description(&self) -> &str {
14        "Task not found"
15    }
16
17    fn cause(&self) -> Option<&(dyn std::error::Error)> {
18        // Generic error, underlying cause isn't tracked.
19        None
20    }
21}
22
23#[derive(Debug, Clone)]
24pub struct TaskIsAlreadyRunning {
25    pub taskname: String,
26}
27
28impl Display for TaskIsAlreadyRunning {
29    fn fmt(&self, f: &mut Formatter) -> Result {
30        write!(f, "{}", format!("{} is already running", self.taskname))
31    }
32}
33
34impl std::error::Error for TaskIsAlreadyRunning {
35    fn description(&self) -> &str {
36        "Task is already running"
37    }
38
39    fn cause(&self) -> Option<&(dyn std::error::Error)> {
40        // Generic error, underlying cause isn't tracked.
41        None
42    }
43}
44
45#[derive(Debug, Clone)]
46pub struct TaskIsNotRunning {
47    pub taskname: String,
48}
49
50impl Display for TaskIsNotRunning {
51    fn fmt(&self, f: &mut Formatter) -> Result {
52        write!(f, "{}", format!("{} is not running", self.taskname))
53    }
54}
55
56impl std::error::Error for TaskIsNotRunning {
57    fn description(&self) -> &str {
58        "Task is not running"
59    }
60
61    fn cause(&self) -> Option<&(dyn std::error::Error)> {
62        // Generic error, underlying cause isn't tracked.
63        None
64    }
65}