maple_render_core/
error.rs1use std::path::PathBuf;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug)]
6pub enum Error {
7 Io(std::io::Error),
8 Image(image::ImageError),
9 Zip(zip::result::ZipError),
10 Json(serde_json::Error),
11 MissingFile(String),
12 MissingData(String),
13 InvalidTemplate(String),
14 FileNotFound(PathBuf),
15 NoRenders,
16 NoMapping,
17 NoRepository,
18 NoInputs,
19 GifEncode(String),
20 VideoEncode(String),
21 TextRender(String),
22 Other(String),
23}
24
25impl std::fmt::Display for Error {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 Error::Io(e) => write!(f, "IO error: {}", e),
29 Error::Image(e) => write!(f, "Image error: {}", e),
30 Error::Zip(e) => write!(f, "Zip error: {}", e),
31 Error::Json(e) => write!(f, "JSON error: {}", e),
32 Error::MissingFile(name) => write!(f, "Missing file: {}", name),
33 Error::MissingData(msg) => write!(f, "Missing data: {}", msg),
34 Error::InvalidTemplate(msg) => write!(f, "Invalid template: {}", msg),
35 Error::FileNotFound(path) => write!(f, "File not found: {}", path.display()),
36 Error::NoRenders => write!(f, "No renders attached"),
37 Error::NoMapping => write!(f, "No mapping attached"),
38 Error::NoRepository => write!(f, "No repository attached"),
39 Error::NoInputs => write!(f, "No inputs attached"),
40 Error::GifEncode(msg) => write!(f, "GIF encoding error: {}", msg),
41 Error::VideoEncode(msg) => write!(f, "Video encoding error: {}", msg),
42 Error::TextRender(msg) => write!(f, "Text rendering error: {}", msg),
43 Error::Other(msg) => write!(f, "{}", msg),
44 }
45 }
46}
47
48impl std::error::Error for Error {
49 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
50 match self {
51 Error::Io(e) => Some(e),
52 Error::Image(e) => Some(e),
53 Error::Zip(e) => Some(e),
54 Error::Json(e) => Some(e),
55 _ => None,
56 }
57 }
58}
59
60impl From<std::io::Error> for Error {
61 fn from(e: std::io::Error) -> Self {
62 Error::Io(e)
63 }
64}
65
66impl From<image::ImageError> for Error {
67 fn from(e: image::ImageError) -> Self {
68 Error::Image(e)
69 }
70}
71
72impl From<zip::result::ZipError> for Error {
73 fn from(e: zip::result::ZipError) -> Self {
74 Error::Zip(e)
75 }
76}
77
78impl From<serde_json::Error> for Error {
79 fn from(e: serde_json::Error) -> Self {
80 Error::Json(e)
81 }
82}
83
84impl From<String> for Error {
85 fn from(s: String) -> Self {
86 Error::Other(s)
87 }
88}
89
90impl From<&str> for Error {
91 fn from(s: &str) -> Self {
92 Error::Other(s.to_string())
93 }
94}