charts_rs/charts/
error.rs1use snafu::Snafu;
20
21#[derive(Debug, Snafu)]
22#[snafu(visibility(pub(crate)))]
23pub enum Error {
24 #[snafu(display("Params is invalid: {message}"))]
25 Params { message: String },
26 #[snafu(display("Json is invalid: {source}"))]
27 Json { source: serde_json::Error },
28 #[snafu(display("Error font: {name} not found"))]
29 FontNotFound { name: String },
30 #[snafu(display("Error parse font: {message}"))]
31 ParseFont { message: String },
32
33 #[cfg(feature = "image-encoder")]
36 #[snafu(display("Io {file}: {source}"))]
37 Io {
38 file: String,
39 source: std::io::Error,
40 },
41 #[cfg(feature = "image-encoder")]
42 #[snafu(display("Image size is invalid, width: {width}, height: {height}"))]
43 Size { width: u32, height: u32 },
44 #[cfg(feature = "image-encoder")]
45 #[snafu(display("Image from raw is fail, size:{size}"))]
46 Raw { size: usize },
47 #[cfg(feature = "image-encoder")]
48 #[snafu(display("Error to parse: {source}"))]
49 Parse { source: resvg::usvg::Error },
50 #[cfg(feature = "image-encoder")]
51 #[snafu(display("Encode fail: {source}"))]
52 Image { source: image::ImageError },
53}
54
55impl From<serde_json::Error> for Error {
56 fn from(value: serde_json::Error) -> Self {
57 Error::Json { source: value }
58 }
59}
60
61impl From<&str> for Error {
62 fn from(value: &str) -> Self {
63 Error::ParseFont {
64 message: value.to_string(),
65 }
66 }
67}
68
69pub type Result<T, E = Error> = std::result::Result<T, E>;