beamterm_renderer/
error.rs1#[derive(thiserror::Error, Debug)]
3pub enum Error {
4 #[error("Initialization error: {0}")]
6 Initialization(String),
7
8 #[error("Shader error: {0}")]
10 Shader(String),
11
12 #[error("Resource error: {0}")]
14 Resource(String),
15
16 #[error("Data error: {0}")]
18 Data(String),
19}
20
21impl Error {
22 pub fn window_not_found() -> Self {
26 Self::Initialization("Unable to retrieve window".to_string())
27 }
28
29 pub fn document_not_found() -> Self {
30 Self::Initialization("Unable to retrieve document".to_string())
31 }
32
33 pub fn canvas_not_found() -> Self {
34 Self::Initialization("Unable to retrieve canvas".to_string())
35 }
36
37 pub fn webgl_context_failed() -> Self {
38 Self::Initialization("Failed to retrieve WebGL2 rendering context".to_string())
39 }
40
41 pub fn canvas_context_failed() -> Self {
42 Self::Initialization("Failed to retrieve canvas rendering context".to_string())
43 }
44
45 pub fn shader_creation_failed(detail: &str) -> Self {
47 Self::Shader(format!("Shader creation failed: {}", detail))
48 }
49
50 pub fn shader_program_creation_failed() -> Self {
51 Self::Shader("Shader program creation failed".to_string())
52 }
53
54 pub fn shader_link_failed(log: String) -> Self {
55 Self::Shader(format!("Shader linking failed: {}", log))
56 }
57
58 pub fn buffer_creation_failed(buffer_type: &str) -> Self {
60 Self::Resource(format!("Failed to create {} buffer", buffer_type))
61 }
62
63 pub fn vertex_array_creation_failed() -> Self {
64 Self::Resource("Failed to create vertex array object".to_string())
65 }
66
67 pub fn texture_creation_failed() -> Self {
68 Self::Resource("Failed to create texture".to_string())
69 }
70
71 pub fn uniform_location_failed(name: &str) -> Self {
72 Self::Resource(format!("Failed to get uniform location: {}", name))
73 }
74
75 pub fn webgl_error(message: String) -> Self {
76 Self::Resource(format!("WebGL error: {}", message))
77 }
78
79 pub fn element_creation_failed(element_type: &str) -> Self {
80 Self::Resource(format!("Failed to create element: {}", element_type))
81 }
82
83 pub fn image_load_failed(path: &str) -> Self {
85 Self::Data(format!("Failed to load image: {}", path))
86 }
87
88 pub fn deserialization_failed(message: String) -> Self {
89 Self::Data(format!("Failed to deserialize: {}", message))
90 }
91}