use thiserror::Error;
#[derive(Error, Debug)]
pub enum ChartError {
#[error("GPU error: {0}")]
Gpu(#[from] wgpu::RequestDeviceError),
#[error("GPU surface error: {0}")]
Surface(#[from] wgpu::SurfaceError),
#[error("GPU device lost")]
DeviceLost,
#[error("GPU out of memory")]
OutOfMemory,
#[error("Invalid data: {0}")]
InvalidData(String),
#[error("Empty dataset")]
EmptyData,
#[error("Data range error: {message}")]
DataRange { message: String },
#[error("Shader compilation failed: {0}")]
ShaderCompilation(String),
#[error("Texture creation failed: {0}")]
TextureCreation(String),
#[error("Buffer creation failed: {0}")]
BufferCreation(String),
#[error("Invalid configuration: {0}")]
InvalidConfig(String),
#[error("Unsupported feature: {0}")]
UnsupportedFeature(String),
#[error("Layer error: {0}")]
Layer(String),
#[error("Layer not found: {0}")]
LayerNotFound(String),
#[error("Text rendering error: {0}")]
TextRendering(String),
#[error("Font loading error: {0}")]
FontLoading(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Internal error: {0}")]
Internal(String),
#[error("Not implemented: {0}")]
NotImplemented(String),
}
pub type Result<T> = std::result::Result<T, ChartError>;
impl ChartError {
pub fn data_range(message: impl Into<String>) -> Self {
Self::DataRange {
message: message.into(),
}
}
pub fn invalid_config(message: impl Into<String>) -> Self {
Self::InvalidConfig(message.into())
}
pub fn layer(message: impl Into<String>) -> Self {
Self::Layer(message.into())
}
pub fn internal(message: impl Into<String>) -> Self {
Self::Internal(message.into())
}
}
impl From<wgpu::BufferAsyncError> for ChartError {
fn from(_: wgpu::BufferAsyncError) -> Self {
Self::internal("GPU buffer operation failed")
}
}