1use std::fmt::{Display, Formatter};
2
3pub type RuntimeResult<T> = std::result::Result<T, RuntimeError>;
5
6#[derive(Debug)]
8pub enum RuntimeError {
9 Core(cymule_core::CoreError),
11 Plugin(String),
13 Suspended(String),
15 Io(String),
17 Encoding(String),
19}
20
21impl Display for RuntimeError {
22 fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
23 match self {
24 Self::Core(error) => Display::fmt(error, formatter),
25 Self::Plugin(message) => write!(formatter, "plugin_error: {message}"),
26 Self::Suspended(message) => write!(formatter, "run_suspended: {message}"),
27 Self::Io(message) => write!(formatter, "io_error: {message}"),
28 Self::Encoding(message) => write!(formatter, "encoding_error: {message}"),
29 }
30 }
31}
32
33impl std::error::Error for RuntimeError {}
34
35impl From<cymule_core::CoreError> for RuntimeError {
36 fn from(error: cymule_core::CoreError) -> Self {
37 Self::Core(error)
38 }
39}
40
41impl From<std::io::Error> for RuntimeError {
42 fn from(error: std::io::Error) -> Self {
43 Self::Io(error.to_string())
44 }
45}
46
47impl From<serde_json::Error> for RuntimeError {
48 fn from(error: serde_json::Error) -> Self {
49 Self::Encoding(error.to_string())
50 }
51}