1use std::path::PathBuf;
2
3#[derive(thiserror::Error, Debug)]
4pub enum Error {
5 #[error("DirMissing: {path}")]
6 DirMissing { path: PathBuf },
7
8 #[error("EmptyChoose: {text}")]
9 EmptyChoose { text: String },
10
11 #[error("GitHub: {err}: {url}")]
12 GitHub { err: String, url: String },
13
14 #[error("Io: {err}: {path}")]
15 Io {
16 #[source]
17 err: std::io::Error,
18 path: PathBuf,
19 },
20
21 #[cfg(feature = "playback")]
22 #[error("RodioPlayError: {err}")]
23 RodioPlay {
24 #[from]
25 err: rodio::PlayError,
26 },
27
28 #[cfg(feature = "playback")]
29 #[error("RodioStreamError: {err}")]
30 RodioStream {
31 #[from]
32 err: rodio::StreamError,
33 },
34
35 #[error("RodioDecoder: {err}: {sound_path}")]
36 RodioDecoder {
37 #[source]
38 err: rodio::decoder::DecoderError,
39 sound_path: String,
40 },
41
42 #[error("Msgpack: {err}: {url}")]
43 Msgpack {
44 #[source]
45 err: rmp_serde::decode::Error,
46 url: String,
47 },
48
49 #[error("Json: {err}: {url}")]
50 Json {
51 #[source]
52 err: serde_json::Error,
53 url: String,
54 },
55
56 #[error("ReqwestMakeClientError: {err}")]
57 ReqwestMakeClient {
58 #[source]
59 err: reqwest::Error,
60 },
61
62 #[error("Reqwest: {err}: {url}")]
63 Reqwest {
64 #[source]
65 err: reqwest::Error,
66 url: String,
67 },
68
69 #[error("ReqwestStatus: {status}: {url}")]
70 ReqwestStatus {
71 status: reqwest::StatusCode,
72 url: String,
73 },
74
75 #[error("InvalidHeaderValue: {err}: {url}")]
76 InvalidHeaderValue {
77 #[source]
78 err: reqwest::header::InvalidHeaderValue,
79 url: String,
80 },
81
82 #[error("Nom: {err}: {text}")]
83 Nom {
84 #[source]
85 err: nom::Err<nom::error::Error<String>>,
86 text: String,
87 },
88}
89
90pub type Result<T> = std::result::Result<T, Error>;
91
92#[macro_export]
93macro_rules! ensure {
94 ($test:expr, $err:expr) => {
95 if !$test {
96 return Err($err);
97 }
98 };
99}
100
101#[macro_export]
102macro_rules! bail {
103 ($err:expr) => {
104 return Err($err);
105 };
106}