1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum FsdMessageParseError {
5 #[error("invalid field count. Expected {0}, found {1}.")]
6 InvalidFieldCount(usize, usize),
7 #[error("{0} is not a valid rating")]
8 InvalidRating(String),
9 #[error("{0} is not a valid protocol revision")]
10 InvalidProtocolRevison(String),
11 #[error("{0} is not a valid flight rules")]
12 InvalidFlightRules(String),
13 #[error("{0} is not a valid simulator type")]
14 InvalidSimulatorType(String),
15 #[error("{0} is not a valid ATC type")]
16 InvalidAtcType(String),
17 #[error("{0} is not a valid time")]
18 InvalidTime(String),
19 #[error("{0} is not a valid minute")]
20 InvalidMinute(String),
21 #[error("{0} is not a valid index")]
22 InvalidIndex(String),
23 #[error("{0} is not a valid ATC frequency")]
24 InvalidFrequency(String),
25 #[error("{0} is not a valid visibility range")]
26 InvalidVisRange(String),
27 #[error("{0} is not a valid lat / long coordinate")]
28 InvalidCoordinate(String),
29 #[error("{0} is not a transponder mode")]
30 InvalidTransponderMode(String),
31 #[error("{0} is not a transponder code")]
32 InvalidTransponderCode(String),
33 #[error("Unable to parse aircraft config: {0}")]
34 InvalidAircraftConfig(String),
35 #[error("{0} is not a valid pitch / bank / heading number")]
36 InvalidPitchBankHeading(String),
37 #[error("{0} is not a valid altitude")]
38 InvalidAltitude(String),
39 #[error("{0} is not a valid altitude difference")]
40 InvalidAltitudeDifference(String),
41 #[error("{0} is not a valid voice capability")]
42 InvalidVoiceCapability(String),
43 #[error("{0} is not a valid speed")]
44 InvalidSpeed(String),
45 #[error("{0} is not a valid client ID")]
46 InvalidClientID(String),
47 #[error("{0} is not a valid version number part")]
48 InvalidVersionNumber(String),
49 #[error("{0} is not a valid nosewheel angle")]
50 InvalidNosewheelAngle(String),
51 #[error("{0} is not a valid position velocity")]
52 InvalidPositionVelocity(String),
53 #[error("Unknown message type: {0}")]
54 UnknownMessageType(String),
55 #[error("{0} is not a valid ping time")]
56 InvalidPingTime(String),
57 #[error("{0} is not a valid server error")]
58 InvalidServerError(String),
59 #[error("{0} is not a valid client query type")]
60 InvalidClientQueryType(String),
61 #[error("{0} is not a valid new ATIS message")]
62 InvalidNewAtisMessage(String),
63 #[error("{0} is not a valid valid ATC status")]
64 InvalidValidAtcStatus(String),
65 #[error("{0} is not a valid valid ATIS line")]
66 InvalidATISLine(String),
67 #[error("{0} is not a valid valid shared state type")]
68 InvalidSharedStateType(String),
69 #[error("{0} is not a valid client capability")]
70 InvalidClientCapability(String),
71 #[error("{0} is not a valid IP addrees")]
72 InvalidIPAddress(String),
73 #[error("{0} is not a valid port")]
74 InvalidPort(String),
75}
76
77#[derive(Debug, Clone, Error)]
79pub enum FsdError {
80 #[error("Callsign in use")]
82 CallsignInUse,
83 #[error("Invalid callsign")]
85 InvalidCallsign,
86 #[error("Already registered")]
88 AlreadyRegistered,
89 #[error("Syntax error")]
91 SyntaxError,
92 #[error("Invalid source callsign")]
94 InvalidSourceCallsign,
95 #[error("Invalid CID / password")]
97 InvalidCidPassword,
98 #[error("No such callsign as {0}")]
100 NoSuchCallsign(String),
101 #[error("No flight plan for {0}")]
103 NoFlightPlan(String),
104 #[error("No weather profile for {0}")]
106 NoWeatherProfile(String),
107 #[error("Invalid protocol revision")]
109 InvalidProtocolRevision,
110 #[error("Requested level too high")]
112 RequestedLevelTooHigh,
113 #[error("Server full")]
115 ServerFull,
116 #[error("CID has been suspended")]
118 CertificateSuspended,
119 #[error("Invalid control")]
121 InvalidControl,
122 #[error("Invalid position for rating")]
124 InvalidPositionForRating,
125 #[error("Unauthorised client")]
127 UnauthorisedClient,
128 #[error("Authentication time out")]
130 AuthTimeOut,
131 #[error("Other: {0}")]
133 Other(String),
134}
135impl FsdError {
136 pub fn error_number(&self) -> u8 {
137 match *self {
138 FsdError::CallsignInUse => 1,
139 FsdError::InvalidCallsign => 2,
140 FsdError::AlreadyRegistered => 3,
141 FsdError::SyntaxError => 4,
142 FsdError::InvalidSourceCallsign => 5,
143 FsdError::InvalidCidPassword => 6,
144 FsdError::NoSuchCallsign(_) => 7,
145 FsdError::NoFlightPlan(_) => 8,
146 FsdError::NoWeatherProfile(_) => 9,
147 FsdError::InvalidProtocolRevision => 10,
148 FsdError::RequestedLevelTooHigh => 11,
149 FsdError::ServerFull => 12,
150 FsdError::CertificateSuspended => 13,
151 FsdError::InvalidControl => 14,
152 FsdError::InvalidPositionForRating => 15,
153 FsdError::UnauthorisedClient => 16,
154 FsdError::AuthTimeOut => 17,
155 FsdError::Other(_) => 18,
156 }
157 }
158}