1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
use std::error::Error;
use std::fmt;
/// Stable, machine-readable parse failure categories.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ErrorCode {
/// The packet header is present but the information field is empty.
PacketNoBody,
/// The packet does not satisfy the general TNC2/APRS structure.
PacketInvalid,
/// The source callsign is not followed by the `>` separator.
SourceNoSeparator,
/// The source callsign is empty.
SourceEmpty,
/// The source callsign contains invalid characters.
SourceInvalid,
/// The destination callsign is empty.
DestinationEmpty,
/// The destination does not satisfy the required AX.25 form.
DestinationInvalid,
/// A strict AX.25 path contains more than eight digipeaters.
PathTooLong,
/// A digipeater path component is empty.
DigipeaterEmpty,
/// A digipeater callsign contains invalid characters.
DigipeaterInvalid,
/// The APRS data-type identifier is unsupported.
TypeNotSupported,
/// An uncompressed position is too short.
PositionShort,
/// A position contains invalid coordinates or syntax.
PositionInvalid,
/// Position ambiguity is inconsistent or invalid.
PositionAmbiguity,
/// The APRS symbol-table identifier is invalid.
SymbolTableInvalid,
/// A compressed position is too short.
CompressedPositionShort,
/// A compressed position contains invalid base-91 data.
CompressedPositionInvalid,
/// An object report is too short.
ObjectShort,
/// An object report has invalid syntax.
ObjectInvalid,
/// An item report is too short.
ItemShort,
/// An item report has invalid syntax.
ItemInvalid,
/// A message is too short to contain an addressee and separator.
MessageShort,
/// A message has invalid syntax.
MessageInvalid,
/// A message being encoded has no destination.
MessageNoDestination,
/// A message destination exceeds the APRS nine-character limit.
MessageDestinationTooLong,
/// A message ID is empty, too long, or non-alphanumeric.
MessageIdInvalid,
/// A reply-ack cannot be represented in the available message-ID space.
MessageReplyAck,
/// Message acknowledgement and rejection fields conflict.
MessageAckReject,
/// A message contains a carriage return or line feed.
MessageNewline,
/// Position or object data cannot be encoded with the supplied values.
PositionEncodeInvalid,
/// An NMEA sentence is too short.
NmeaShort,
/// An NMEA sentence is malformed or has an invalid checksum.
NmeaInvalid,
/// An NMEA RMC sentence reports that no navigation fix is available.
NmeaNoFix,
/// A telemetry report is malformed.
TelemetryInvalid,
/// A telemetry value exceeds FAP's conventional range but was preserved.
TelemetryTooLarge,
/// A weather report is malformed.
WeatherInvalid,
/// An experimental APRS packet format is not supported.
ExperimentalUnsupported,
/// A Mic-E information field is too short.
MicEShort,
/// A Mic-E destination field cannot be decoded.
MicEDestinationInvalid,
/// A Mic-E information field cannot be decoded.
MicEInformationInvalid,
}
impl ErrorCode {
/// Compatibility-style string identifier, based on FAP error names.
pub const fn as_str(self) -> &'static str {
match self {
Self::PacketNoBody => "packet_no_body",
Self::PacketInvalid => "packet_inv",
Self::SourceNoSeparator => "srccall_nogt",
Self::SourceEmpty => "srccall_empty",
Self::SourceInvalid => "srccall_badchars",
Self::DestinationEmpty => "dstcall_empty",
Self::DestinationInvalid => "dstcall_noax25",
Self::PathTooLong => "dstpath_toomany",
Self::DigipeaterEmpty => "digi_empty",
Self::DigipeaterInvalid => "digicall_badchars",
Self::TypeNotSupported => "type_not_supported",
Self::PositionShort => "pos_short",
Self::PositionInvalid => "loc_inv",
Self::PositionAmbiguity => "loc_amb_inv",
Self::SymbolTableInvalid => "sym_inv_table",
Self::CompressedPositionShort => "comp_short",
Self::CompressedPositionInvalid => "comp_inv",
Self::ObjectShort => "obj_short",
Self::ObjectInvalid => "obj_inv",
Self::ItemShort => "item_short",
Self::ItemInvalid => "item_inv",
Self::MessageShort => "msg_short",
Self::MessageInvalid => "msg_inv",
Self::MessageNoDestination => "msg_no_dst",
Self::MessageDestinationTooLong => "msg_dst_long",
Self::MessageIdInvalid => "msg_id_inv",
Self::MessageReplyAck => "msg_replyack",
Self::MessageAckReject => "msg_ack_rej",
Self::MessageNewline => "msg_cr",
Self::PositionEncodeInvalid => "pos_enc_inv",
Self::NmeaShort => "nmea_short",
Self::NmeaInvalid => "nmea_invalid",
Self::NmeaNoFix => "gprmc_nofix",
Self::TelemetryInvalid => "tlm_inv",
Self::TelemetryTooLarge => "tlm_large",
Self::WeatherInvalid => "wx_inv",
Self::ExperimentalUnsupported => "exp_unsupp",
Self::MicEShort => "mice_short",
Self::MicEDestinationInvalid => "mice_inv_dstcall",
Self::MicEInformationInvalid => "mice_inv_infofield",
}
}
}
/// A parse error with a stable code and a specific explanation.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseError {
/// Stable category suitable for programmatic matching.
pub code: ErrorCode,
/// Human-readable detail about the specific failure.
pub message: String,
}
impl ParseError {
pub(crate) fn new(code: ErrorCode, message: impl Into<String>) -> Self {
Self {
code,
message: message.into(),
}
}
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "frap: {}: {}", self.code.as_str(), self.message)
}
}
impl Error for ParseError {}