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
163
164
165
166
167
168
169
pub mod error;
pub mod error_inner;
pub mod id_error;
pub mod index_error;
pub mod parse_error;
#[cfg(feature = "app")]
pub mod portaudio_error;
pub use error::Error;
pub use error_inner::ErrorInner;
pub use id_error::IdError;
pub use index_error::IndexError;
pub use parse_error::ParseError;
#[cfg(feature = "app")]
use portaudio_error::PortAudioError;
use scop::ScopError;
use serde::{Deserialize, Serialize};
use std::io;
#[derive(Debug, Serialize, Deserialize)]
pub enum Serializable {
Msg(String),
Scope(ScopError),
IoError(String),
HoundError(String),
#[cfg(feature = "app")]
#[serde(with = "PortAudioError")]
PortAudio(weresocool_portaudio::error::Error),
SerdeJsonError(String),
CsvError(String),
ParseError(ParseError),
IdError(IdError),
IndexError(IndexError),
#[cfg(all(feature = "app", not(target_os = "windows")))]
LameError(weresocool_lame::Error),
#[cfg(all(feature = "app", not(target_os = "windows")))]
LameEncodeError(weresocool_lame::EncodeError),
}
impl ErrorInner {
pub fn into_serializeable(self) -> Serializable {
match self {
ErrorInner::Msg(e) => Serializable::Msg(e),
ErrorInner::ScopeError(e) => Serializable::Scope(e),
ErrorInner::ParseError(e) => Serializable::ParseError(e),
ErrorInner::IdError(e) => Serializable::IdError(e),
ErrorInner::IndexError(e) => Serializable::IndexError(e),
#[cfg(feature = "app")]
ErrorInner::PortAudio(e) => Serializable::PortAudio(e),
#[cfg(all(feature = "app", not(target_os = "windows")))]
ErrorInner::LameError(e) => Serializable::LameError(e),
#[cfg(all(feature = "app", not(target_os = "windows")))]
ErrorInner::LameEncodeError(e) => Serializable::LameEncodeError(e),
ErrorInner::Io(e) => {
println!("{:#?}", e);
Serializable::IoError("".to_string())
}
ErrorInner::SerdeJson(e) => {
println!("{:#?}", e);
Serializable::SerdeJsonError("SerdeJson Error".to_string())
}
ErrorInner::CsvError(e) => {
println!("{:#?}", e);
Serializable::CsvError("CsvError".to_string())
}
ErrorInner::HoundError(e) => {
println!("{:#?}", e);
Serializable::HoundError("HoundError".to_string())
}
}
}
}
impl<'a> From<&'a str> for Error {
fn from(msg: &'a str) -> Error {
Error::with_msg(msg)
}
}
impl From<IdError> for Error {
fn from(e: IdError) -> Error {
Error {
inner: Box::new(ErrorInner::IdError(e)),
}
}
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Error {
Error {
inner: Box::new(ErrorInner::Io(e)),
}
}
}
#[cfg(any(feature = "app", feature = "windows"))]
impl From<weresocool_portaudio::error::Error> for Error {
fn from(e: weresocool_portaudio::error::Error) -> Error {
Error {
inner: Box::new(ErrorInner::PortAudio(e)),
}
}
}
impl From<serde_json::error::Error> for Error {
fn from(e: serde_json::error::Error) -> Error {
Error {
inner: Box::new(ErrorInner::SerdeJson(e)),
}
}
}
impl From<csv::Error> for Error {
fn from(e: csv::Error) -> Error {
Error {
inner: Box::new(ErrorInner::CsvError(e)),
}
}
}
impl From<scop::ScopError> for Error {
fn from(e: scop::ScopError) -> Error {
Error {
inner: Box::new(ErrorInner::ScopeError(e)),
}
}
}
impl From<ParseError> for Error {
fn from(e: ParseError) -> Error {
Error {
inner: Box::new(ErrorInner::ParseError(e)),
}
}
}
impl From<hound::Error> for Error {
fn from(e: hound::Error) -> Error {
Error {
inner: Box::new(ErrorInner::HoundError(e)),
}
}
}
#[cfg(all(feature = "app", not(target_os = "windows")))]
impl From<weresocool_lame::Error> for Error {
fn from(e: weresocool_lame::Error) -> Error {
Error {
inner: Box::new(ErrorInner::LameError(e)),
}
}
}
#[cfg(all(feature = "app", not(target_os = "windows")))]
impl From<weresocool_lame::EncodeError> for Error {
fn from(e: weresocool_lame::EncodeError) -> Error {
Error {
inner: Box::new(ErrorInner::LameEncodeError(e)),
}
}
}
#[test]
fn size_of_error_is_one_word() {
use std::mem;
assert_eq!(mem::size_of::<Error>(), mem::size_of::<usize>());
}