1#[derive(thiserror::Error, Debug)]
9#[non_exhaustive]
10pub enum ConversionError {
11 #[error("Conversion error: {value} is out of range for {type_name}")]
12 Range { value: String, type_name: String },
13 #[error("Conversion error: The object name you have provided \"{0}\" is {1} characters and too long. The maximum length is 15 characters.")]
14 ObjectNameTooLong(String, usize),
15 #[error("Conversion error: The object name you have provided \"{0}\" contains non-ascii characters.")]
16 ObjectNameNotAscii(String),
17 #[error("Conversion error: The input value in the string needs to represent an integer.")]
18 ParseIntError(#[from] std::num::ParseIntError),
19}
20
21#[derive(thiserror::Error, Debug)]
25#[non_exhaustive]
26pub enum ParameterError {
27 #[error("Parameter error: {value} is out of range for {parameter_name}")]
28 Range {
29 value: String,
30 parameter_name: String,
31 },
32
33 #[error("Parameter error: {value} is not compatible with {parameter_name}. {reason:?}")]
34 Compatibility {
35 value: String,
36 parameter_name: String,
37 reason: Option<String>,
38 },
39}
40
41#[derive(thiserror::Error, Debug)]
45#[non_exhaustive]
46pub enum SysexConversionError {
47 #[error("Not a sysex message")]
48 NotASysexMsg,
49 #[error("Short read on sysex message")]
50 ShortRead,
51 #[error("End of message too soon")]
52 EndOfMessage,
53 #[error("Abort")]
54 Abort,
55 #[error("Invalid manufacturer ID")]
56 InvalidManufacturerId,
57 #[error("Invalid product ID")]
58 InvalidProductId,
59 #[error("Invalid dump message ID")]
60 InvalidDumpMsgId,
61 #[error("Invalid object type")]
62 InvalidObjType,
63 #[error("Checksum error")]
64 Chksum,
65 #[error("Null pointer")]
66 Nullptr,
67 #[error("Invalid object number")]
68 InvalidObjNr,
69 #[error("Not a pattern")]
70 NotAPattern,
71 #[error("Not a kit")]
72 NotAKit,
73 #[error("Not a sound")]
74 NotASound,
75 #[error("The type of the sysex message does not match the size of the message. Expected {0} got {1}")]
76 InvalidSize(usize, usize),
77 #[error("Unknown error code: {0}")]
78 Unknown(u8),
79 #[error("Sysex type of {0} is encountered but not implemented yet.")]
80 Unimplemented(String),
81}
82
83impl From<u8> for SysexConversionError {
84 fn from(code: u8) -> Self {
85 match code {
86 1 => Self::NotASysexMsg,
87 2 => Self::ShortRead,
88 3 => Self::EndOfMessage,
89 4 => Self::Abort,
90 5 => Self::InvalidManufacturerId,
91 6 => Self::InvalidProductId,
92 7 => Self::InvalidDumpMsgId,
93 8 => Self::InvalidObjType,
94 9 => Self::Chksum,
95 10 => Self::Nullptr,
96 11 => Self::InvalidObjNr,
97 12 => Self::NotAPattern,
98 13 => Self::NotAKit,
99 14 => Self::NotASound,
100 _ => Self::Unknown(code),
101 }
102 }
103}
104
105#[derive(thiserror::Error, Debug)]
107#[non_exhaustive]
108pub enum RytmError {
109 #[error("{0}")]
110 Custom(String),
111 #[error(transparent)]
112 Conversion(#[from] ConversionError),
113 #[error(transparent)]
114 Parameter(#[from] ParameterError),
115 #[error(transparent)]
116 SysexConversion(#[from] SysexConversionError),
117
118 #[error(transparent)]
119 Serde(#[from] serde_json::Error),
120
121 #[error("Parameter lock memory full.")]
122 ParameterLockMemoryFull,
123 #[error("Parameter lock pool is not set for this trig thus it is not connected to a pattern and orphan. This function can not be called on an orphan trig.")]
124 OrphanTrig,
125}