Skip to content

Commit cafad42

Browse files
authored
Add exception handling (#104)
* Add exception handling * Update WAMR's hash --------- Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
1 parent e9d8d04 commit cafad42

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

src/ocre/components/container_supervisor/cs_sm_impl.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,23 @@ static void container_thread_entry(void *args) {
131131
// Set TLS for the container's WASM module
132132
current_module_tls = &module_inst;
133133
#endif
134-
// Run the WASM main function
135-
bool success = wasm_application_execute_main(module_inst, 0, NULL);
134+
135+
// Run the WASM main function with exception handling
136+
bool success = false;
137+
const char *exception = NULL;
138+
139+
// Clear any previous exceptions
140+
wasm_runtime_clear_exception(module_inst);
141+
142+
// Execute main function
143+
success = wasm_application_execute_main(module_inst, 0, NULL);
144+
145+
// Check for exceptions
146+
exception = wasm_runtime_get_exception(module_inst);
147+
if (exception) {
148+
LOG_ERR("Container %d exception: %s", container->container_ID, exception);
149+
success = false;
150+
}
136151
// Update container status
137152
if (container->container_runtime_status != CONTAINER_STATUS_STOPPED)
138153
container->container_runtime_status = success ? CONTAINER_STATUS_STOPPED : CONTAINER_STATUS_ERROR;
@@ -161,7 +176,12 @@ static void container_thread_entry(void *args) {
161176
}
162177
core_mutex_unlock(&container->lock);
163178

164-
LOG_INF("Container thread %d exited cleanly", container->container_ID);
179+
if (success) {
180+
LOG_INF("Container %d completed successfully", container->container_ID);
181+
} else {
182+
LOG_ERR("Container %d failed: %s", container->container_ID,
183+
exception ? exception : "unknown error");
184+
}
165185

166186
// Clean up WASM runtime thread environment
167187
wasm_runtime_destroy_thread_env();

src/ocre/ocre_gpio/ocre_gpio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ int ocre_gpio_unregister_callback(int pin) {
267267

268268
void ocre_gpio_cleanup_container(wasm_module_inst_t module_inst) {
269269
if (!gpio_system_initialized || !module_inst) {
270-
LOG_ERR("GPIO system not initialized or invalid module %p", (void *)module_inst);
270+
LOG_DBG("GPIO system not initialized or invalid module %p", (void *)module_inst);
271271
return;
272272
}
273273
for (int i = 0; i < CONFIG_OCRE_GPIO_MAX_PINS; i++) {

wasm-micro-runtime

0 commit comments

Comments
 (0)