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 #[error("RodioPlayError: {err}")]
22 RodioPlay {
23 #[from]
24 err: rodio::PlayError,
25 },
26
27 #[error("RodioStreamError: {err}")]
28 RodioStream {
29 #[from]
30 err: rodio::StreamError,
31 },
32
33 #[error("RodioDecoder: {err}: {sound_path}")]
34 RodioDecoder {
35 #[source]
36 err: rodio::decoder::DecoderError,
37 sound_path: String,
38 },
39
40 #[error("Msgpack: {err}: {url}")]
41 Msgpack {
42 #[source]
43 err: rmp_serde::decode::Error,
44 url: String,
45 },
46
47 #[error("Json: {err}: {url}")]
48 Json {
49 #[source]
50 err: serde_json::Error,
51 url: String,
52 },
53
54 #[error("ReqwestMakeClientError: {err}")]
55 ReqwestMakeClient {
56 #[source]
57 err: reqwest::Error,
58 },
59
60 #[error("Reqwest: {err}: {url}")]
61 Reqwest {
62 #[source]
63 err: reqwest::Error,
64 url: String,
65 },
66
67 #[error("ReqwestStatus: {status}: {url}")]
68 ReqwestStatus {
69 status: reqwest::StatusCode,
70 url: String,
71 },
72
73 #[error("InvalidHeaderValue: {err}: {url}")]
74 InvalidHeaderValue {
75 #[source]
76 err: reqwest::header::InvalidHeaderValue,
77 url: String,
78 },
79
80 #[error("Nom: {err}: {text}")]
81 Nom {
82 #[source]
83 err: nom::Err<nom::error::Error<String>>,
84 text: String,
85 },
86}
87
88pub type Result<T> = std::result::Result<T, Error>;
89
90#[macro_export]
91macro_rules! ensure {
92 ($test:expr, $err:expr) => {
93 if !$test {
94 return Err($err);
95 }
96 };
97}
98
99#[macro_export]
100macro_rules! bail {
101 ($err:expr) => {
102 return Err($err);
103 };
104}