Skip to content

Commit 62917f2

Browse files
committed
record adding export function failures in chain
1 parent 4528649 commit 62917f2

File tree

1 file changed

+211
-44
lines changed

1 file changed

+211
-44
lines changed

crates/theater/src/host/handler.rs

Lines changed: 211 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
use crate::actor::handle::ActorHandle;
22
use crate::config::permissions::*;
3+
use crate::events::{
4+
environment::EnvironmentEventData,
5+
filesystem::FilesystemEventData,
6+
http::HttpEventData,
7+
message::MessageEventData,
8+
process::ProcessEventData,
9+
random::RandomEventData,
10+
runtime::RuntimeEventData,
11+
store::StoreEventData,
12+
supervisor::SupervisorEventData,
13+
timing::TimingEventData,
14+
ChainEventData, EventData,
15+
};
316
use crate::host::environment::EnvironmentHost;
417
use crate::host::filesystem::FileSystemHost;
518
use crate::host::framework::HttpFramework;
@@ -137,50 +150,204 @@ impl Handler {
137150

138151
pub async fn add_export_functions(&self, actor_instance: &mut ActorInstance) -> Result<()> {
139152
match self {
140-
Handler::MessageServer(handler, _) => Ok(handler
141-
.add_export_functions(actor_instance)
142-
.await
143-
.expect("Error adding functions to message server")),
144-
Handler::Environment(handler, _) => Ok(handler
145-
.add_export_functions(actor_instance)
146-
.await
147-
.expect("Error adding functions to environment handler")),
148-
Handler::FileSystem(handler, _) => Ok(handler
149-
.add_export_functions(actor_instance)
150-
.await
151-
.expect("Error adding functions to filesystem")),
152-
Handler::HttpClient(handler, _) => Ok(handler
153-
.add_export_functions(actor_instance)
154-
.await
155-
.expect("Error adding functions to http client")),
156-
Handler::HttpFramework(handler, _) => Ok(handler
157-
.add_export_functions(actor_instance)
158-
.await
159-
.expect("Error adding functions to http framework")),
160-
Handler::Process(handler, _) => Ok(handler
161-
.add_export_functions(actor_instance)
162-
.await
163-
.expect("Error adding functions to process handler")),
164-
Handler::Runtime(handler, _) => Ok(handler
165-
.add_export_functions(actor_instance)
166-
.await
167-
.expect("Error adding functions to runtime")),
168-
Handler::Supervisor(handler, _) => Ok(handler
169-
.add_export_functions(actor_instance)
170-
.await
171-
.expect("Error adding functions to supervisor")),
172-
Handler::Store(handler, _) => Ok(handler
173-
.add_export_functions(actor_instance)
174-
.await
175-
.expect("Error adding functions to store")),
176-
Handler::Timing(handler, _) => Ok(handler
177-
.add_export_functions(actor_instance)
178-
.await
179-
.expect("Error adding functions to timing")),
180-
Handler::Random(handler, _) => Ok(handler
181-
.add_export_functions(actor_instance)
182-
.await
183-
.expect("Error adding functions to random")),
153+
Handler::MessageServer(handler, _) => {
154+
match handler.add_export_functions(actor_instance).await {
155+
Ok(_) => Ok(()),
156+
Err(e) => {
157+
let error_msg = format!("Error adding functions to message server: {}", e);
158+
actor_instance.actor_component.actor_store.record_event(ChainEventData {
159+
event_type: "message-server-export-setup".to_string(),
160+
data: EventData::Message(MessageEventData::HandlerSetupError {
161+
error: error_msg.clone(),
162+
step: "add_export_functions".to_string(),
163+
}),
164+
timestamp: chrono::Utc::now().timestamp_millis() as u64,
165+
description: Some(error_msg),
166+
});
167+
Err(e)
168+
}
169+
}
170+
}
171+
Handler::Environment(handler, _) => {
172+
match handler.add_export_functions(actor_instance).await {
173+
Ok(_) => Ok(()),
174+
Err(e) => {
175+
let error_msg = format!("Error adding functions to environment handler: {}", e);
176+
actor_instance.actor_component.actor_store.record_event(ChainEventData {
177+
event_type: "environment-export-setup".to_string(),
178+
data: EventData::Environment(EnvironmentEventData::HandlerSetupError {
179+
error: error_msg.clone(),
180+
step: "add_export_functions".to_string(),
181+
}),
182+
timestamp: chrono::Utc::now().timestamp_millis() as u64,
183+
description: Some(error_msg),
184+
});
185+
Err(e)
186+
}
187+
}
188+
}
189+
Handler::FileSystem(handler, _) => {
190+
match handler.add_export_functions(actor_instance).await {
191+
Ok(_) => Ok(()),
192+
Err(e) => {
193+
let error_msg = format!("Error adding functions to filesystem: {}", e);
194+
actor_instance.actor_component.actor_store.record_event(ChainEventData {
195+
event_type: "filesystem-export-setup".to_string(),
196+
data: EventData::Filesystem(FilesystemEventData::HandlerSetupError {
197+
error: error_msg.clone(),
198+
step: "add_export_functions".to_string(),
199+
}),
200+
timestamp: chrono::Utc::now().timestamp_millis() as u64,
201+
description: Some(error_msg),
202+
});
203+
Err(e)
204+
}
205+
}
206+
}
207+
Handler::HttpClient(handler, _) => {
208+
match handler.add_export_functions(actor_instance).await {
209+
Ok(_) => Ok(()),
210+
Err(e) => {
211+
let error_msg = format!("Error adding functions to http client: {}", e);
212+
actor_instance.actor_component.actor_store.record_event(ChainEventData {
213+
event_type: "http-client-export-setup".to_string(),
214+
data: EventData::Http(HttpEventData::HandlerSetupError {
215+
error: error_msg.clone(),
216+
step: "add_export_functions".to_string(),
217+
}),
218+
timestamp: chrono::Utc::now().timestamp_millis() as u64,
219+
description: Some(error_msg),
220+
});
221+
Err(e)
222+
}
223+
}
224+
}
225+
Handler::HttpFramework(handler, _) => {
226+
match handler.add_export_functions(actor_instance).await {
227+
Ok(_) => Ok(()),
228+
Err(e) => {
229+
let error_msg = format!("Error adding functions to http framework: {}", e);
230+
actor_instance.actor_component.actor_store.record_event(ChainEventData {
231+
event_type: "http-framework-export-setup".to_string(),
232+
data: EventData::Http(HttpEventData::HandlerSetupError {
233+
error: error_msg.clone(),
234+
step: "add_export_functions".to_string(),
235+
}),
236+
timestamp: chrono::Utc::now().timestamp_millis() as u64,
237+
description: Some(error_msg),
238+
});
239+
Err(e)
240+
}
241+
}
242+
}
243+
Handler::Process(handler, _) => {
244+
match handler.add_export_functions(actor_instance).await {
245+
Ok(_) => Ok(()),
246+
Err(e) => {
247+
let error_msg = format!("Error adding functions to process handler: {}", e);
248+
actor_instance.actor_component.actor_store.record_event(ChainEventData {
249+
event_type: "process-export-setup".to_string(),
250+
data: EventData::Process(ProcessEventData::HandlerSetupError {
251+
error: error_msg.clone(),
252+
step: "add_export_functions".to_string(),
253+
}),
254+
timestamp: chrono::Utc::now().timestamp_millis() as u64,
255+
description: Some(error_msg),
256+
});
257+
Err(e)
258+
}
259+
}
260+
}
261+
Handler::Runtime(handler, _) => {
262+
match handler.add_export_functions(actor_instance).await {
263+
Ok(_) => Ok(()),
264+
Err(e) => {
265+
let error_msg = format!("Error adding functions to runtime: {}", e);
266+
actor_instance.actor_component.actor_store.record_event(ChainEventData {
267+
event_type: "runtime-export-setup".to_string(),
268+
data: EventData::Runtime(RuntimeEventData::HandlerSetupError {
269+
error: error_msg.clone(),
270+
step: "add_export_functions".to_string(),
271+
}),
272+
timestamp: chrono::Utc::now().timestamp_millis() as u64,
273+
description: Some(error_msg),
274+
});
275+
Err(e)
276+
}
277+
}
278+
}
279+
Handler::Supervisor(handler, _) => {
280+
match handler.add_export_functions(actor_instance).await {
281+
Ok(_) => Ok(()),
282+
Err(e) => {
283+
let error_msg = format!("Error adding functions to supervisor: {}", e);
284+
actor_instance.actor_component.actor_store.record_event(ChainEventData {
285+
event_type: "supervisor-export-setup".to_string(),
286+
data: EventData::Supervisor(SupervisorEventData::HandlerSetupError {
287+
error: error_msg.clone(),
288+
step: "add_export_functions".to_string(),
289+
}),
290+
timestamp: chrono::Utc::now().timestamp_millis() as u64,
291+
description: Some(error_msg),
292+
});
293+
Err(e)
294+
}
295+
}
296+
}
297+
Handler::Store(handler, _) => {
298+
match handler.add_export_functions(actor_instance).await {
299+
Ok(_) => Ok(()),
300+
Err(e) => {
301+
let error_msg = format!("Error adding functions to store: {}", e);
302+
actor_instance.actor_component.actor_store.record_event(ChainEventData {
303+
event_type: "store-export-setup".to_string(),
304+
data: EventData::Store(StoreEventData::HandlerSetupError {
305+
error: error_msg.clone(),
306+
step: "add_export_functions".to_string(),
307+
}),
308+
timestamp: chrono::Utc::now().timestamp_millis() as u64,
309+
description: Some(error_msg),
310+
});
311+
Err(e)
312+
}
313+
}
314+
}
315+
Handler::Timing(handler, _) => {
316+
match handler.add_export_functions(actor_instance).await {
317+
Ok(_) => Ok(()),
318+
Err(e) => {
319+
let error_msg = format!("Error adding functions to timing: {}", e);
320+
actor_instance.actor_component.actor_store.record_event(ChainEventData {
321+
event_type: "timing-export-setup".to_string(),
322+
data: EventData::Timing(TimingEventData::HandlerSetupError {
323+
error: error_msg.clone(),
324+
step: "add_export_functions".to_string(),
325+
}),
326+
timestamp: chrono::Utc::now().timestamp_millis() as u64,
327+
description: Some(error_msg),
328+
});
329+
Err(e)
330+
}
331+
}
332+
}
333+
Handler::Random(handler, _) => {
334+
match handler.add_export_functions(actor_instance).await {
335+
Ok(_) => Ok(()),
336+
Err(e) => {
337+
let error_msg = format!("Error adding functions to random: {}", e);
338+
actor_instance.actor_component.actor_store.record_event(ChainEventData {
339+
event_type: "random-export-setup".to_string(),
340+
data: EventData::Random(RandomEventData::HandlerSetupError {
341+
error: error_msg.clone(),
342+
step: "add_export_functions".to_string(),
343+
}),
344+
timestamp: chrono::Utc::now().timestamp_millis() as u64,
345+
description: Some(error_msg),
346+
});
347+
Err(e)
348+
}
349+
}
350+
}
184351
}
185352
}
186353

0 commit comments

Comments
 (0)