quickjs_rusty/errors/
execution_error.rs1use std::{error, fmt};
2
3use crate::OwnedJsValue;
4
5use super::ValueError;
6
7#[derive(Debug)]
9pub enum ExecutionError {
10 InputWithZeroBytes,
12 Conversion(ValueError),
14 Internal(String),
16 Exception(OwnedJsValue),
18 OutOfMemory,
20 #[doc(hidden)]
21 __NonExhaustive,
22}
23
24impl fmt::Display for ExecutionError {
25 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26 use ExecutionError::*;
27 match self {
28 InputWithZeroBytes => write!(f, "Invalid script input: code contains zero byte (\\0)"),
29 Conversion(e) => e.fmt(f),
30 Internal(e) => write!(f, "Internal error: {}", e),
31 Exception(e) => {
32 if e.is_string() {
33 write!(f, "{}", e.to_string().unwrap())
34 } else {
35 write!(f, "JS Exception: {:?}", e)
36 }
37 }
38 OutOfMemory => write!(f, "Out of memory: runtime memory limit exceeded"),
39 __NonExhaustive => unreachable!(),
40 }
41 }
42}
43
44impl PartialEq for ExecutionError {
45 fn eq(&self, other: &Self) -> bool {
46 let left = self.to_string();
47 let right = other.to_string();
48 left == right
49 }
50}
51
52impl error::Error for ExecutionError {}
53
54impl From<ValueError> for ExecutionError {
55 fn from(v: ValueError) -> Self {
56 ExecutionError::Conversion(v)
57 }
58}