veloren_voxygen/render/
error.rs

1/// Used to represent one of many possible errors that may be omitted by the
2/// rendering subsystem.
3pub enum RenderError {
4    RequestDeviceError(wgpu::RequestDeviceError),
5    MappingError(wgpu::BufferAsyncError),
6    SurfaceError(wgpu::SurfaceError),
7    CustomError(String),
8    CouldNotFindAdapter,
9    RequestAdapterError(wgpu::RequestAdapterError),
10    ErrorInitializingShaderCCompiler(shaderc::Error),
11    ShaderShaderCError(String, shaderc::Error),
12    ShaderWgpuError(String, wgpu::Error),
13}
14
15use std::fmt;
16impl fmt::Debug for RenderError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            Self::RequestDeviceError(err) => {
20                f.debug_tuple("RequestDeviceError").field(err).finish()
21            },
22            Self::MappingError(err) => f.debug_tuple("MappingError").field(err).finish(),
23            Self::SurfaceError(err) => f
24                .debug_tuple("SurfaceError")
25                // Use Display formatting for this error since they have nice descriptions
26                .field(&format!("{}", err))
27                .finish(),
28            Self::CustomError(err) => f.debug_tuple("CustomError").field(err).finish(),
29            Self::CouldNotFindAdapter => f.debug_tuple("CouldNotFindAdapter").finish(),
30            Self::RequestAdapterError(err) => f
31                .debug_tuple("RequestAdapterError")
32                // Use Display formatting for this error since they have nice descriptions
33                .field(&err.to_string())
34                .finish(),
35            Self::ErrorInitializingShaderCCompiler(err) => f
36                .debug_tuple("ErrorInitializingShaderCCompiler")
37                .field(err)
38                .finish(),
39            Self::ShaderShaderCError(shader_name, err) => write!(
40                f,
41                "\"{shader_name}\" shader failed to compile with shaderc due to the following \
42                 error: {err}",
43            ),
44            Self::ShaderWgpuError(shader_name, err) => write!(
45                f,
46                "\"{shader_name}\" shader failed to compile with wgpu due to the following error: \
47                 {err}",
48            ),
49        }
50    }
51}
52
53impl From<wgpu::RequestDeviceError> for RenderError {
54    fn from(err: wgpu::RequestDeviceError) -> Self { Self::RequestDeviceError(err) }
55}
56
57impl From<wgpu::BufferAsyncError> for RenderError {
58    fn from(err: wgpu::BufferAsyncError) -> Self { Self::MappingError(err) }
59}
60
61impl From<wgpu::SurfaceError> for RenderError {
62    fn from(err: wgpu::SurfaceError) -> Self { Self::SurfaceError(err) }
63}
64
65impl From<wgpu::RequestAdapterError> for RenderError {
66    fn from(err: wgpu::RequestAdapterError) -> Self { Self::RequestAdapterError(err) }
67}
68
69impl From<shaderc::Error> for RenderError {
70    fn from(err: shaderc::Error) -> Self { Self::ErrorInitializingShaderCCompiler(err) }
71}
72
73impl From<(&str, shaderc::Error)> for RenderError {
74    fn from((shader_name, err): (&str, shaderc::Error)) -> Self {
75        Self::ShaderShaderCError(shader_name.into(), err)
76    }
77}