datex_core/runtime/execution/
errors.rs1use crate::dxb_parser::body::DXBParserError;
2use crate::network::com_hub::ResponseError;
3use crate::references::reference::{
4 AccessError, AssignmentError, ReferenceCreationError,
5};
6use crate::runtime::execution::execution_loop::state::ExecutionLoopState;
7use crate::stdlib::string::String;
8use crate::types::error::IllegalTypeError;
9use crate::values::value_container::{ValueContainer, ValueError};
10use core::fmt::Display;
11
12#[derive(Debug, Clone, PartialEq, Eq)]
13pub enum InvalidProgramError {
14 UnterminatedSequence,
16 MissingRemoteExecutionReceiver,
17 ExpectedTypeValue,
18 ExpectedValue,
19 ExpectedInstruction,
20 ExpectedRegularInstruction,
21 ExpectedTypeInstruction,
22}
23
24impl Display for InvalidProgramError {
25 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
26 match self {
27 InvalidProgramError::UnterminatedSequence => {
28 core::write!(f, "Unterminated sequence")
29 }
30 InvalidProgramError::MissingRemoteExecutionReceiver => {
31 core::write!(f, "Missing remote execution receiver")
32 }
33 InvalidProgramError::ExpectedTypeValue => {
34 core::write!(f, "Expected a type value")
35 }
36 InvalidProgramError::ExpectedValue => {
37 core::write!(f, "Expected a value")
38 }
39 InvalidProgramError::ExpectedRegularInstruction => {
40 core::write!(f, "Expected a regular instruction")
41 }
42 InvalidProgramError::ExpectedTypeInstruction => {
43 core::write!(f, "Expected a type instruction")
44 }
45 InvalidProgramError::ExpectedInstruction => {
46 core::write!(f, "Expected an instruction")
47 }
48 }
49 }
50}
51
52#[derive(Debug)]
53pub enum ExecutionError {
54 DXBParserError(DXBParserError),
55 ValueError(ValueError),
56 InvalidProgram(InvalidProgramError),
57 AccessError(AccessError),
58 Unknown,
59 NotImplemented(String),
60 SlotNotAllocated(u32),
61 SlotNotInitialized(u32),
62 RequiresAsyncExecution,
63 RequiresRuntime,
64 ResponseError(ResponseError),
65 IllegalTypeError(IllegalTypeError),
66 ReferenceNotFound,
67 DerefOfNonReference,
68 InvalidTypeCast,
69 ExpectedTypeValue,
70 AssignmentError(AssignmentError),
71 ReferenceFromValueContainerError(ReferenceCreationError),
72 IntermediateResultWithState(
73 Option<ValueContainer>,
74 Option<ExecutionLoopState>,
75 ),
76 InvalidApply,
77}
78impl From<ReferenceCreationError> for ExecutionError {
79 fn from(error: ReferenceCreationError) -> Self {
80 ExecutionError::ReferenceFromValueContainerError(error)
81 }
82}
83
84impl From<AccessError> for ExecutionError {
85 fn from(error: AccessError) -> Self {
86 ExecutionError::AccessError(error)
87 }
88}
89
90impl From<DXBParserError> for ExecutionError {
91 fn from(error: DXBParserError) -> Self {
92 ExecutionError::DXBParserError(error)
93 }
94}
95
96impl From<ValueError> for ExecutionError {
97 fn from(error: ValueError) -> Self {
98 ExecutionError::ValueError(error)
99 }
100}
101
102impl From<IllegalTypeError> for ExecutionError {
103 fn from(error: IllegalTypeError) -> Self {
104 ExecutionError::IllegalTypeError(error)
105 }
106}
107
108impl From<InvalidProgramError> for ExecutionError {
109 fn from(error: InvalidProgramError) -> Self {
110 ExecutionError::InvalidProgram(error)
111 }
112}
113
114impl From<ResponseError> for ExecutionError {
115 fn from(error: ResponseError) -> Self {
116 ExecutionError::ResponseError(error)
117 }
118}
119
120impl From<AssignmentError> for ExecutionError {
121 fn from(error: AssignmentError) -> Self {
122 ExecutionError::AssignmentError(error)
123 }
124}
125
126impl Display for ExecutionError {
127 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
128 match self {
129 ExecutionError::ReferenceFromValueContainerError(err) => {
130 core::write!(f, "Reference from value container error: {err}")
131 }
132 ExecutionError::ReferenceNotFound => {
133 core::write!(f, "Reference not found")
134 }
135 ExecutionError::DXBParserError(err) => {
136 core::write!(f, "Parser error: {err}")
137 }
138 ExecutionError::Unknown => {
139 core::write!(f, "Unknown execution error")
140 }
141 ExecutionError::ValueError(err) => {
142 core::write!(f, "Value error: {err}")
143 }
144 ExecutionError::InvalidProgram(err) => {
145 core::write!(f, "Invalid program error: {err}")
146 }
147 ExecutionError::NotImplemented(msg) => {
148 core::write!(f, "Not implemented: {msg}")
149 }
150 ExecutionError::SlotNotAllocated(address) => {
151 core::write!(
152 f,
153 "Tried to access unallocated slot at address {address}"
154 )
155 }
156 ExecutionError::SlotNotInitialized(address) => {
157 core::write!(
158 f,
159 "Tried to access uninitialized slot at address {address}"
160 )
161 }
162 ExecutionError::RequiresAsyncExecution => {
163 core::write!(f, "Program must be executed asynchronously")
164 }
165 ExecutionError::RequiresRuntime => {
166 core::write!(f, "Execution requires a runtime to be set")
167 }
168 ExecutionError::ResponseError(err) => {
169 core::write!(f, "Response error: {err}")
170 }
171 ExecutionError::IllegalTypeError(err) => {
172 core::write!(f, "Illegal type: {err}")
173 }
174 ExecutionError::DerefOfNonReference => {
175 core::write!(f, "Tried to dereference a non-reference value")
176 }
177 ExecutionError::AssignmentError(err) => {
178 core::write!(f, "Assignment error: {err}")
179 }
180 ExecutionError::InvalidTypeCast => {
181 core::write!(f, "Invalid type cast")
182 }
183 ExecutionError::ExpectedTypeValue => {
184 core::write!(f, "Expected a type value")
185 }
186 ExecutionError::AccessError(err) => {
187 core::write!(f, "Access error: {err}")
188 }
189 ExecutionError::IntermediateResultWithState(
190 value_opt,
191 state_opt,
192 ) => {
193 core::write!(
194 f,
195 "Execution produced an intermediate result: {:?} with state: {:?}",
196 value_opt,
197 state_opt
198 )
199 }
200 ExecutionError::InvalidApply => {
201 core::write!(f, "Invalid apply operation")
202 }
203 }
204 }
205}