Skip to main content

wgsl_fft/
error.rs

1//! Error types for the wgsl-fft crate
2
3use std::io;
4
5use thiserror::Error;
6
7/// Main error type for FFT operations
8#[derive(Debug, Error)]
9pub enum FftError {
10    /// Input validation error (wrong size, empty, etc.)
11    #[error("Input validation error: {0}")]
12    ValidationError(String),
13
14    /// WGPU-related error
15    #[error("WGPU error: {0}")]
16    WgpuError(String),
17
18    /// I/O error
19    #[error("I/O error: {0}")]
20    IoError(#[from] io::Error),
21
22    /// No GPU device available
23    #[error("No GPU device available")]
24    NoDevice,
25
26    /// Invalid FFT size
27    #[error("Invalid FFT size: {0}")]
28    InvalidSize(String),
29
30    /// Compute shader error
31    #[error("Compute shader error: {0}")]
32    ShaderError(String),
33
34    /// Batch processing error
35    #[error("Batch processing error: {0}")]
36    BatchError(String),
37
38    /// GPU backend error (CUDA, HIP, ROCm)
39    #[error("GPU backend error: {0}")]
40    BackendError(String),
41
42    /// Generic error message
43    #[error("{0}")]
44    Other(String),
45}
46
47/// Result type alias for FFT operations
48pub type Result<T> = std::result::Result<T, FftError>;
49
50/// Convert wgpu::Error to FftError
51impl From<wgpu::Error> for FftError {
52    fn from(e: wgpu::Error) -> Self {
53        Self::WgpuError(e.to_string())
54    }
55}
56
57/// Convert wgpu::PollError to FftError
58impl From<wgpu::PollError> for FftError {
59    fn from(e: wgpu::PollError) -> Self {
60        Self::WgpuError(e.to_string())
61    }
62}
63
64/// Convert wgpu::RequestAdapterError to FftError
65impl From<wgpu::RequestAdapterError> for FftError {
66    fn from(e: wgpu::RequestAdapterError) -> Self {
67        Self::WgpuError(e.to_string())
68    }
69}
70
71/// Convert wgpu::RequestDeviceError to FftError
72impl From<wgpu::RequestDeviceError> for FftError {
73    fn from(e: wgpu::RequestDeviceError) -> Self {
74        Self::WgpuError(e.to_string())
75    }
76}