-
Notifications
You must be signed in to change notification settings - Fork 153
/
Copy patherror.rs
85 lines (78 loc) · 2.15 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
use crate::WrongSizeError;
use quick_error::quick_error;
use std::io;
use std::num::TryFromIntError;
quick_error! {
#[derive(Debug)]
pub enum Error {
/// Internal error
ThreadSend {
display("Internal error; unexpectedly aborted")
}
Aborted {
display("aborted")
}
Gifsicle {
display("gifsicle failure")
}
Gif(err: gif::EncodingError) {
display("GIF encoding error: {}", err)
}
NoFrames {
display("Found no usable frames to encode")
}
Io(err: io::Error) {
from()
from(_oom: std::collections::TryReserveError) -> (io::ErrorKind::OutOfMemory.into())
display("I/O: {}", err)
}
PNG(msg: String) {
display("{}", msg)
}
WrongSize(msg: String) {
display("{}", msg)
from(e: TryFromIntError) -> (e.to_string())
from(_e: WrongSizeError) -> ("wrong size".to_string())
from(e: resize::Error) -> (e.to_string())
}
Quant(liq: imagequant::liq_error) {
from()
display("pngquant error: {}", liq)
}
Pal(gif: gif_dispose::Error) {
from()
display("gif dispose error: {}", gif)
}
}
}
#[doc(hidden)]
pub type CatResult<T, E = Error> = Result<T, E>;
/// Alias for `Result` with gifski's [`Error`]
pub type GifResult<T, E = Error> = Result<T, E>;
impl From<gif::EncodingError> for Error {
#[cold]
fn from(err: gif::EncodingError) -> Self {
match err {
gif::EncodingError::Io(err) => err.into(),
other => Self::Gif(other),
}
}
}
impl<T> From<ordered_channel::SendError<T>> for Error {
#[cold]
fn from(_: ordered_channel::SendError<T>) -> Self {
Self::ThreadSend
}
}
impl From<ordered_channel::RecvError> for Error {
#[cold]
fn from(_: ordered_channel::RecvError) -> Self {
Self::Aborted
}
}
impl From<Box<dyn std::any::Any + Send>> for Error {
#[cold]
fn from(_panic: Box<dyn std::any::Any + Send>) -> Self {
Self::ThreadSend
}
}