-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy patherror.rs
93 lines (86 loc) · 2.4 KB
/
error.rs
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
use std::{
io,
num::{ParseFloatError, ParseIntError},
result,
str::Utf8Error,
};
use thiserror::Error;
#[cfg(feature = "png")]
use image::error::ImageError;
#[cfg(feature = "png")]
use png::{DecodingError, EncodingError};
#[cfg(feature = "unzip")]
use zip::result::ZipError;
pub type Result<T> = result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("Illegal null character in string.")]
Null,
#[error("Invalid UTF-8 character at position {position}.")]
Utf8 { source: Utf8Error, position: usize },
#[error("Invalid or empty filename specified.")]
InvalidFilename,
#[error(transparent)]
Io(#[from] io::Error),
#[error("Invalid algorithm specified.")]
InvalidAlgorithm,
#[cfg(feature = "png")]
#[error(transparent)]
ImageDecoding(#[from] DecodingError),
#[cfg(feature = "png")]
#[error(transparent)]
ImageEncoding(#[from] EncodingError),
#[cfg(feature = "http")]
#[error(transparent)]
JsonSerialization(#[from] serde_json::Error),
#[error(transparent)]
ParseInt(#[from] ParseIntError),
#[error(transparent)]
ParseFloat(#[from] ParseFloatError),
#[error(transparent)]
GenericImage(#[from] ImageError),
#[cfg(feature = "png")]
#[error("Invalid png data.")]
InvalidPngData,
#[cfg(feature = "http")]
#[error(transparent)]
Request(#[from] Box<ureq::Error>),
#[cfg(feature = "sound_len")]
#[error("SoundLen error: {0}")]
SoundLen(String),
#[cfg(feature = "toml")]
#[error(transparent)]
TomlDeserialization(#[from] toml_dep::de::Error),
#[cfg(feature = "toml")]
#[error(transparent)]
TomlSerialization(#[from] toml_dep::ser::Error),
#[cfg(feature = "unzip")]
#[error(transparent)]
Unzip(#[from] ZipError),
#[cfg(feature = "hash")]
#[error("Unable to decode hex value.")]
HexDecode,
#[cfg(feature = "iconforge")]
#[error("IconForge error: {0}")]
IconForge(String),
#[error("Panic during function execution: {0}")]
Panic(String),
}
impl From<Utf8Error> for Error {
fn from(source: Utf8Error) -> Self {
Self::Utf8 {
source,
position: source.valid_up_to(),
}
}
}
impl From<Error> for String {
fn from(error: Error) -> Self {
error.to_string()
}
}
impl From<Error> for Vec<u8> {
fn from(error: Error) -> Self {
error.to_string().into_bytes()
}
}