Skip to content

Commit 770e3fd

Browse files
authored
add panic shim to Sequencer (#143)
1 parent 49f2237 commit 770e3fd

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

crates/ct_worker/shim.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import shim, {
2+
Sequencer, Batcher, Cleaner, __wbg_reset_state,
3+
} from "./build/worker/shim.mjs";
4+
5+
// no-op worker entrypoint for now
6+
const WorkerEntrypointProxy = new Proxy(shim, {});
7+
8+
const DOProxy = new Proxy(Sequencer, {
9+
construct(target, args) {
10+
const state = args[0] // get state
11+
// const env = args[1] // get env
12+
try {
13+
const instance = new target(...args);
14+
15+
return new Proxy(instance, {
16+
get(target, prop, receiver) {
17+
const original = Reflect.get(target, prop, receiver);
18+
// Check if the property is a function
19+
if (typeof original === 'function') {
20+
return new Proxy(original, {
21+
async apply(target, thisArg, argArray) {
22+
try {
23+
const resultPromise = await target.bind(thisArg, ...argArray)();
24+
// const resultPromise = await target.bind(thisArg, ...argArray)()
25+
return resultPromise;
26+
} catch (e) {
27+
if (e.message == "memory access out of bounds") {
28+
console.error(e)
29+
__wbg_reset_state();
30+
state.abort("Call to DO panicked, force-restarting DO")
31+
return new Response("Worker panicked... restarting DO")
32+
}
33+
throw e;
34+
}
35+
36+
37+
}
38+
});
39+
}
40+
return original; // Return the property directly if it's not a function
41+
}
42+
});
43+
44+
} catch (err) {
45+
__wbg_reset_state();
46+
state.abort("Constructor for DO panicked, force-restarting DO")
47+
}
48+
},
49+
});
50+
51+
export { DOProxy as Sequencer, Batcher, Cleaner, WorkerEntrypointProxy as default };

crates/ct_worker/wrangler.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "static-ct",
3-
"main": "build/worker/shim.mjs",
3+
"main": "./shim.js",
44
"compatibility_date": "2025-09-25",
55
"workers_dev": false,
66
"build": {

0 commit comments

Comments
 (0)