1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum ChartError {
8 #[error("GPU error: {0}")]
10 Gpu(#[from] wgpu::RequestDeviceError),
11
12 #[error("GPU surface error: {0}")]
13 Surface(#[from] wgpu::SurfaceError),
14
15 #[error("GPU device lost")]
16 DeviceLost,
17
18 #[error("GPU out of memory")]
19 OutOfMemory,
20
21 #[error("Invalid data: {0}")]
23 InvalidData(String),
24
25 #[error("Empty dataset")]
26 EmptyData,
27
28 #[error("Data range error: {message}")]
29 DataRange { message: String },
30
31 #[error("Shader compilation failed: {0}")]
33 ShaderCompilation(String),
34
35 #[error("Texture creation failed: {0}")]
36 TextureCreation(String),
37
38 #[error("Buffer creation failed: {0}")]
39 BufferCreation(String),
40
41 #[error("Invalid configuration: {0}")]
43 InvalidConfig(String),
44
45 #[error("Unsupported feature: {0}")]
46 UnsupportedFeature(String),
47
48 #[error("Layer error: {0}")]
50 Layer(String),
51
52 #[error("Layer not found: {0}")]
53 LayerNotFound(String),
54
55 #[error("Text rendering error: {0}")]
57 TextRendering(String),
58
59 #[error("Font loading error: {0}")]
60 FontLoading(String),
61
62 #[error("I/O error: {0}")]
64 Io(#[from] std::io::Error),
65
66 #[error("Serialization error: {0}")]
67 Serialization(#[from] serde_json::Error),
68
69 #[error("Internal error: {0}")]
71 Internal(String),
72
73 #[error("Not implemented: {0}")]
74 NotImplemented(String),
75}
76
77pub type Result<T> = std::result::Result<T, ChartError>;
79
80impl ChartError {
81 pub fn data_range(message: impl Into<String>) -> Self {
83 Self::DataRange {
84 message: message.into(),
85 }
86 }
87
88 pub fn invalid_config(message: impl Into<String>) -> Self {
90 Self::InvalidConfig(message.into())
91 }
92
93 pub fn layer(message: impl Into<String>) -> Self {
95 Self::Layer(message.into())
96 }
97
98 pub fn internal(message: impl Into<String>) -> Self {
100 Self::Internal(message.into())
101 }
102}
103
104impl From<wgpu::BufferAsyncError> for ChartError {
106 fn from(_: wgpu::BufferAsyncError) -> Self {
107 Self::internal("GPU buffer operation failed")
108 }
109}
110
111