midi_io/midi/
parse_error.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
2#[non_exhaustive]
3pub enum ParseError {
4 #[error("empty message")]
5 Empty,
6 #[error("truncated message")]
7 Truncated,
8 #[error("unexpected trailing bytes after message")]
9 TrailingData,
10 #[error("standalone SysexEnd marker")]
11 StandaloneSysexEnd,
12 #[error("data byte with high bit set")]
13 DataByteOutOfRange,
14 #[error("channel out of range")]
15 ChannelOutOfRange,
16 #[error("sysex body byte with high bit set")]
17 SysexDataOutOfRange,
18 #[error("empty sysex body")]
19 EmptySysex,
20 #[error("unterminated sysex")]
21 UnterminatedSysex,
22 #[error("unrecognized status byte")]
23 UnrecognizedStatus,
24 #[error("orphaned data bytes ({len} total)")]
25 OrphanedData { len: usize },
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31
32 #[test]
33 fn parse_error_display() {
34 assert_eq!(format!("{}", ParseError::Empty), "empty message");
35 assert_eq!(format!("{}", ParseError::Truncated), "truncated message");
36 assert_eq!(
37 format!("{}", ParseError::TrailingData),
38 "unexpected trailing bytes after message"
39 );
40 assert_eq!(
41 format!("{}", ParseError::StandaloneSysexEnd),
42 "standalone SysexEnd marker"
43 );
44 assert_eq!(
45 format!("{}", ParseError::DataByteOutOfRange),
46 "data byte with high bit set"
47 );
48 assert_eq!(
49 format!("{}", ParseError::ChannelOutOfRange),
50 "channel out of range"
51 );
52 assert_eq!(
53 format!("{}", ParseError::SysexDataOutOfRange),
54 "sysex body byte with high bit set"
55 );
56 assert_eq!(format!("{}", ParseError::EmptySysex), "empty sysex body");
57 assert_eq!(
58 format!("{}", ParseError::UnterminatedSysex),
59 "unterminated sysex"
60 );
61 assert_eq!(
62 format!("{}", ParseError::UnrecognizedStatus),
63 "unrecognized status byte"
64 );
65 assert_eq!(
66 format!("{}", ParseError::OrphanedData { len: 3 }),
67 "orphaned data bytes (3 total)"
68 );
69 }
70}