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    ErrorInitializingCompiler,
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::ErrorInitializingCompiler => f.debug_tuple("ErrorInitializingCompiler").finish(),
36            Self::ShaderShaderCError(shader_name, err) => write!(
37                f,
38                "\"{shader_name}\" shader failed to compile with shaderc due to the following \
39                 error: {err}",
40            ),
41            Self::ShaderWgpuError(shader_name, err) => write!(
42                f,
43                "\"{shader_name}\" shader failed to compile with wgpu due to the following error: \
44                 {err}",
45            ),
46        }
47    }
48}
49
50impl From<wgpu::RequestDeviceError> for RenderError {
51    fn from(err: wgpu::RequestDeviceError) -> Self { Self::RequestDeviceError(err) }
52}
53
54impl From<wgpu::BufferAsyncError> for RenderError {
55    fn from(err: wgpu::BufferAsyncError) -> Self { Self::MappingError(err) }
56}
57
58impl From<wgpu::SurfaceError> for RenderError {
59    fn from(err: wgpu::SurfaceError) -> Self { Self::SurfaceError(err) }
60}
61
62impl From<wgpu::RequestAdapterError> for RenderError {
63    fn from(err: wgpu::RequestAdapterError) -> Self { Self::RequestAdapterError(err) }
64}
65
66impl From<(&str, shaderc::Error)> for RenderError {
67    fn from((shader_name, err): (&str, shaderc::Error)) -> Self {
68        Self::ShaderShaderCError(shader_name.into(), err)
69    }
70}