1use core::{
2 error::Error,
3 fmt::{self, Display, Formatter},
4};
5use stak_dynamic::DynamicError;
6use stak_r7rs::SmallError;
7use stak_vm::Exception;
8
9#[derive(Debug)]
11pub enum EngineError {
12 Dynamic(DynamicError),
14 Small(SmallError),
16 Vm(stak_vm::Error),
18}
19
20impl From<DynamicError> for EngineError {
21 fn from(error: DynamicError) -> Self {
22 Self::Dynamic(error)
23 }
24}
25
26impl From<SmallError> for EngineError {
27 fn from(error: SmallError) -> Self {
28 Self::Small(error)
29 }
30}
31
32impl From<stak_vm::Error> for EngineError {
33 fn from(error: stak_vm::Error) -> Self {
34 Self::Vm(error)
35 }
36}
37
38impl Exception for EngineError {
39 fn is_critical(&self) -> bool {
40 match self {
41 Self::Dynamic(error) => error.is_critical(),
42 Self::Small(error) => error.is_critical(),
43 Self::Vm(error) => error.is_critical(),
44 }
45 }
46}
47
48impl Error for EngineError {}
49
50impl Display for EngineError {
51 fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
52 match self {
53 Self::Dynamic(error) => write!(formatter, "{error}"),
54 Self::Small(error) => write!(formatter, "{error}"),
55 Self::Vm(error) => write!(formatter, "{error}"),
56 }
57 }
58}