dioxus_document/
error.rs

1use std::error::Error;
2use std::fmt::Display;
3
4/// Represents an error when evaluating JavaScript
5#[derive(Debug)]
6#[non_exhaustive]
7pub enum EvalError {
8    /// The platform does not support evaluating JavaScript.
9    Unsupported,
10
11    /// The provided JavaScript has already been ran.
12    Finished,
13
14    /// The provided JavaScript is not valid and can't be ran.
15    InvalidJs(String),
16
17    /// Represents an error communicating between JavaScript and Rust.
18    Communication(String),
19
20    /// Represents an error serializing or deserializing the result of an eval
21    Serialization(serde_json::Error),
22}
23
24impl Display for EvalError {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        match self {
27            EvalError::Unsupported => write!(f, "EvalError::Unsupported - eval is not supported on the current platform"),
28            EvalError::Finished => write!(f, "EvalError::Finished - eval has already ran"),
29            EvalError::InvalidJs(_) => write!(f, "EvalError::InvalidJs - the provided javascript is invalid"),
30            EvalError::Communication(_) => write!(f, "EvalError::Communication - there was an error trying to communicate with between javascript and rust"),
31            EvalError::Serialization(_) => write!(f, "EvalError::Serialization - there was an error trying to serialize or deserialize the result of an eval"),
32        }
33    }
34}
35
36impl Error for EvalError {}