1use std::fmt;
5
6pub type Result<T, E = Error> = std::result::Result<T, E>;
7
8#[derive(Debug)]
9pub enum Error {
10 AlreadyJoined { name: &'static str },
12
13 EmptyFleet,
15
16 NodeOutsideFleet { node_id: u16, fleet_capacity: u16 },
18
19 Io(std::io::Error),
21}
22
23impl fmt::Display for Error {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 match self {
26 Self::AlreadyJoined { name } => {
27 write!(f, "fleet '{name}' has already been joined in this process")
28 }
29 Self::EmptyFleet => {
30 write!(
31 f,
32 "fleet_capacity must be ≥ 1; Orbit needs at least one node lane"
33 )
34 }
35 Self::NodeOutsideFleet {
36 node_id,
37 fleet_capacity,
38 } => write!(
39 f,
40 "node_id {node_id} is outside fleet_capacity {fleet_capacity}"
41 ),
42 Self::Io(err) => write!(f, "orbit io error: {err}"),
43 }
44 }
45}
46
47impl std::error::Error for Error {
48 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
49 match self {
50 Self::Io(err) => Some(err),
51 _ => None,
52 }
53 }
54}