Skip to main content

quiver/wasm/
error.rs

1//! Error types for WASM bindings
2
3use alloc::format;
4use alloc::string::String;
5use wasm_bindgen::prelude::*;
6
7/// Error type for WASM bindings
8#[wasm_bindgen]
9pub struct QuiverError {
10    message: String,
11}
12
13#[wasm_bindgen]
14impl QuiverError {
15    /// Get the error message
16    #[wasm_bindgen(getter)]
17    pub fn message(&self) -> String {
18        self.message.clone()
19    }
20}
21
22impl From<crate::graph::PatchError> for QuiverError {
23    fn from(e: crate::graph::PatchError) -> Self {
24        Self {
25            message: format!("{:?}", e),
26        }
27    }
28}
29
30impl From<String> for QuiverError {
31    fn from(message: String) -> Self {
32        Self { message }
33    }
34}
35
36impl From<&str> for QuiverError {
37    fn from(message: &str) -> Self {
38        Self {
39            message: message.into(),
40        }
41    }
42}