lighty_launch/instance/
errors.rs1use std::fmt;
2
3pub type InstanceResult<T> = Result<T, InstanceError>;
5
6#[derive(Debug)]
8pub enum InstanceError {
9 NotFound { pid: u32 },
10
11 StillRunning {
12 instance_name: String,
13 pids: Vec<u32>,
14 },
15
16 Io(std::io::Error),
17
18 DuplicatePid {
19 pid: u32,
20 existing_instance: String,
21 },
22}
23
24impl fmt::Display for InstanceError {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 InstanceError::NotFound { pid } => {
28 write!(f, "Instance with PID {} not found", pid)
29 }
30 InstanceError::StillRunning {
31 instance_name,
32 pids,
33 } => {
34 write!(
35 f,
36 "Cannot delete instance '{}': still running with PIDs {:?}",
37 instance_name, pids
38 )
39 }
40 InstanceError::Io(err) => write!(f, "I/O error: {}", err),
41 InstanceError::DuplicatePid { pid, existing_instance } => write!(
42 f,
43 "Cannot register instance: PID {} already tracked by '{}'",
44 pid, existing_instance
45 ),
46 }
47 }
48}
49
50impl std::error::Error for InstanceError {
51 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
52 match self {
53 InstanceError::Io(err) => Some(err),
54 _ => None,
55 }
56 }
57}
58
59impl From<std::io::Error> for InstanceError {
60 fn from(err: std::io::Error) -> Self {
61 InstanceError::Io(err)
62 }
63}