web_sys_query/
error.rs

1use crate::Event;
2use derive_more::From;
3use displaydoc::Display;
4use thiserror::Error;
5use wasm_bindgen::JsValue;
6
7#[derive(Debug, Display, Error, From)]
8pub enum Error {
9    /// Cannot remove attribute: '{0}'
10    #[from(ignore)]
11    CannotRemoveAttribute(String),
12    /// Child element not found: '{0}'
13    #[from(ignore)]
14    ChildElementNotFound(&'static str),
15    /// DOM element not found: '{0}'
16    #[from(ignore)]
17    DomElementNotFound(&'static str),
18    /// Failed to get dynamic reference type
19    DynRefFailed,
20    /// Element ID not found: '{0}'
21    #[from(ignore)]
22    ElementIdNotFound(&'static str),
23    /// Event not implemented: `{0:?}˙
24    EventNotImplemented(Event),
25    /// Event not handled: `{0:?}˙
26    #[from(ignore)]
27    EventNotHandled(Event),
28    /// First element in collection not found
29    FirstElementNotFound,
30    /// Failed to cast to HTML element
31    NotHtmlElement,
32    /// Failed to cast to `EventTarget`
33    NotEventTarget,
34    /// `Document` without document `Element`
35    NoDocumentElement,
36    /// `Event` does not have a target element
37    NoTargetElement,
38    /// `Element` type does not have '{0}' value
39    #[from(ignore)]
40    NoValue(&'static str),
41    /// Selectors Parser Error
42    SelectorsParserError,
43    /// Other Error
44    JsValue(JsValue),
45}
46
47impl Into<JsValue> for Error {
48    fn into(self) -> JsValue {
49        match self {
50            Error::JsValue(value) => value,
51            _ => JsValue::from_str(&self.to_string()),
52        }
53    }
54}