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(
25 &self,
26 f: &mut fmt::Formatter<'_>,
27 ) -> fmt::Result {
28 match self {
29 Self::AlreadyJoined { name } => {
30 write!(
31 f,
32 "fleet '{name}' has already been joined in this process"
33 )
34 }
35 Self::EmptyFleet => {
36 write!(
37 f,
38 "fleet_capacity must be ≥ 1; Orbit needs at least one node lane"
39 )
40 }
41 Self::NodeOutsideFleet { node_id, fleet_capacity } => {
42 write!(
43 f,
44 "node_id {node_id} is outside fleet_capacity {fleet_capacity}"
45 )
46 }
47 Self::Io(err) => write!(f, "orbit io error: {err}"),
48 }
49 }
50}
51
52impl std::error::Error for Error {
53 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
54 match self {
55 Self::Io(err) => Some(err),
56 _ => None,
57 }
58 }
59}