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    ShaderError(String, shaderc::Error),
12}
13
14use std::fmt;
15impl fmt::Debug for RenderError {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match self {
18            Self::RequestDeviceError(err) => {
19                f.debug_tuple("RequestDeviceError").field(err).finish()
20            },
21            Self::MappingError(err) => f.debug_tuple("MappingError").field(err).finish(),
22            Self::SurfaceError(err) => f
23                .debug_tuple("SurfaceError")
24                // Use Display formatting for this error since they have nice descriptions
25                .field(&format!("{}", err))
26                .finish(),
27            Self::CustomError(err) => f.debug_tuple("CustomError").field(err).finish(),
28            Self::CouldNotFindAdapter => f.debug_tuple("CouldNotFindAdapter").finish(),
29            Self::RequestAdapterError(err) => f
30                .debug_tuple("RequestAdapterError")
31                // Use Display formatting for this error since they have nice descriptions
32                .field(&err.to_string())
33                .finish(),
34            Self::ErrorInitializingCompiler => f.debug_tuple("ErrorInitializingCompiler").finish(),
35            Self::ShaderError(shader_name, err) => write!(
36                f,
37                "\"{shader_name}\" shader failed to compile due to the following error: {err}",
38            ),
39        }
40    }
41}
42
43impl From<wgpu::RequestDeviceError> for RenderError {
44    fn from(err: wgpu::RequestDeviceError) -> Self { Self::RequestDeviceError(err) }
45}
46
47impl From<wgpu::BufferAsyncError> for RenderError {
48    fn from(err: wgpu::BufferAsyncError) -> Self { Self::MappingError(err) }
49}
50
51impl From<wgpu::SurfaceError> for RenderError {
52    fn from(err: wgpu::SurfaceError) -> Self { Self::SurfaceError(err) }
53}
54
55impl From<wgpu::RequestAdapterError> for RenderError {
56    fn from(err: wgpu::RequestAdapterError) -> Self { Self::RequestAdapterError(err) }
57}
58
59impl From<(&str, shaderc::Error)> for RenderError {
60    fn from((shader_name, err): (&str, shaderc::Error)) -> Self {
61        Self::ShaderError(shader_name.into(), err)
62    }
63}