#include "demo_guard.h" // Fault-injection demo. Under the wasm runtime every unit fault is a guest // trap that the workspace turns into a clean 500 without harming the worker; // these modes exercise the three distinct trap causes (mirrors tests/wasm-kill). u64 error_reporting_recurse(volatile u64 depth) { volatile u64 next = depth + 1; return(next + error_reporting_recurse(next)); } RENDER(Request& context) { if(!test_demo_request_allowed(context)) { test_demo_render_restricted_html(context, "Error reporting", "crash or abort request workers for diagnostics"); return; } String mode = context.get["mode"]; if(mode == "trap") __builtin_trap(); if(mode == "recurse") { volatile u64 sink = error_reporting_recurse(0); (void)sink; } if(mode == "loop") { volatile u64 i = 0; while(i >= 0) i++; } <>
These actions trigger guest traps so you can verify that UCE returns a usable `500` response from a healthy worker instead of dropping the upstream connection.
> }