summaryrefslogtreecommitdiff
path: root/webhogg/wasm/src/error.rs
diff options
context:
space:
mode:
authorDennis Kobert <d-kobert@web.de>2019-06-21 23:52:07 +0200
committerDennis Kobert <d-kobert@web.de>2019-06-21 23:52:07 +0200
commit4e0037169db5d0c7d824debedb5513b69676506a (patch)
tree82c56547fa70b499627236efa66c3bf7e5411ead /webhogg/wasm/src/error.rs
parent36c89240a87ecb826cf09bc7b3069aa636c9f2f1 (diff)
parent031f63755aada2f1b51eb945fda2a18ad0d24aad (diff)
Merge branch 'wasm' into game_server_refactor
Diffstat (limited to 'webhogg/wasm/src/error.rs')
-rw-r--r--webhogg/wasm/src/error.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/webhogg/wasm/src/error.rs b/webhogg/wasm/src/error.rs
new file mode 100644
index 0000000..fbb6bf8
--- /dev/null
+++ b/webhogg/wasm/src/error.rs
@@ -0,0 +1,36 @@
+use std::error::Error;
+
+#[derive(Debug)]
+pub enum WasmError {
+ WebGl2ContextCreation(String),
+ Shader(String),
+ WebGlBuffer(String),
+}
+
+impl std::fmt::Display for WasmError {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+ write!(f, "{}: {}", self.name(), self.description())
+ }
+}
+
+impl Error for WasmError {
+ fn description(&self) -> &str {
+ match self {
+ WasmError::WebGl2ContextCreation(msg) => msg,
+ WasmError::Shader(msg) => msg,
+ WasmError::WebGlBuffer(msg) => msg,
+ }
+ }
+
+ fn source(&self) -> Option<&'static dyn Error> { None }
+}
+
+impl WasmError {
+ pub fn name(&self) -> &str {
+ match self {
+ WasmError::WebGl2ContextCreation(_) => "WebGl2ContextCreationError",
+ WasmError::Shader(_) => "ShaderError",
+ WasmError::WebGlBuffer(_) => "WebGlBufferError",
+ }
+ }
+}