Skip to content

Commit f81e7d9

Browse files
Overhaul error handling/reporting (#554)
* Update the shared core, fix bad error related_command_index with run proposals * Decorate errors for non completable commands * Decorate errors for restate promises results * Update sdk-shared-core * Revert examples
1 parent 022894b commit f81e7d9

File tree

12 files changed

+695
-184
lines changed

12 files changed

+695
-184
lines changed

package-lock.json

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/restate-sdk-cloudflare-workers/patches/vm/sdk_shared_core_wasm_bindings.d.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ export enum LogLevel {
1616
WARN = 3,
1717
ERROR = 4,
1818
}
19+
export enum WasmCommandType {
20+
Input = 0,
21+
Output = 1,
22+
GetState = 2,
23+
GetStateKeys = 3,
24+
SetState = 4,
25+
ClearState = 5,
26+
ClearAllState = 6,
27+
GetPromise = 7,
28+
PeekPromise = 8,
29+
CompletePromise = 9,
30+
Sleep = 10,
31+
Call = 11,
32+
OneWayCall = 12,
33+
SendSignal = 13,
34+
Run = 14,
35+
AttachInvocation = 15,
36+
GetInvocationOutput = 16,
37+
CompleteAwakeable = 17,
38+
CancelInvocation = 18,
39+
}
1940
export interface WasmFailure {
2041
code: number;
2142
message: string;
@@ -79,6 +100,8 @@ export class WasmVM {
79100
notify_input(buffer: Uint8Array): void;
80101
notify_input_closed(): void;
81102
notify_error(error_message: string, stacktrace?: string | null): void;
103+
notify_error_for_next_command(error_message: string, stacktrace: string | null | undefined, wasm_command_type: WasmCommandType): void;
104+
notify_error_for_specific_command(error_message: string, stacktrace: string | null | undefined, wasm_command_type: WasmCommandType, command_index: number, command_name?: string | null): void;
82105
take_output(): any;
83106
is_ready_to_execute(): boolean;
84107
is_completed(handle: number): boolean;
@@ -105,10 +128,11 @@ export class WasmVM {
105128
sys_run(name: string): number;
106129
propose_run_completion_success(handle: number, buffer: Uint8Array): void;
107130
propose_run_completion_failure(handle: number, value: WasmFailure): void;
108-
propose_run_completion_failure_transient(handle: number, error_message: string, error_stacktrace: string | null | undefined, attempt_duration: bigint, config: WasmExponentialRetryConfig): void;
131+
propose_run_completion_failure_transient(handle: number, error_message: string, error_stacktrace: string | null | undefined, attempt_duration: bigint, config?: WasmExponentialRetryConfig | null): void;
109132
sys_cancel_invocation(target_invocation_id: string): void;
110133
sys_write_output_success(buffer: Uint8Array): void;
111134
sys_write_output_failure(value: WasmFailure): void;
112135
sys_end(): void;
113136
is_processing(): boolean;
137+
last_command_index(): number;
114138
}

packages/restate-sdk-cloudflare-workers/patches/vm/sdk_shared_core_wasm_bindings_bg.js

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,30 @@ export const LogLevel = Object.freeze({
263263
WARN: 3, "3": "WARN",
264264
ERROR: 4, "4": "ERROR",
265265
});
266+
/**
267+
* @enum {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18}
268+
*/
269+
export const WasmCommandType = Object.freeze({
270+
Input: 0, "0": "Input",
271+
Output: 1, "1": "Output",
272+
GetState: 2, "2": "GetState",
273+
GetStateKeys: 3, "3": "GetStateKeys",
274+
SetState: 4, "4": "SetState",
275+
ClearState: 5, "5": "ClearState",
276+
ClearAllState: 6, "6": "ClearAllState",
277+
GetPromise: 7, "7": "GetPromise",
278+
PeekPromise: 8, "8": "PeekPromise",
279+
CompletePromise: 9, "9": "CompletePromise",
280+
Sleep: 10, "10": "Sleep",
281+
Call: 11, "11": "Call",
282+
OneWayCall: 12, "12": "OneWayCall",
283+
SendSignal: 13, "13": "SendSignal",
284+
Run: 14, "14": "Run",
285+
AttachInvocation: 15, "15": "AttachInvocation",
286+
GetInvocationOutput: 16, "16": "GetInvocationOutput",
287+
CompleteAwakeable: 17, "17": "CompleteAwakeable",
288+
CancelInvocation: 18, "18": "CancelInvocation",
289+
});
266290

267291
const WasmHeaderFinalization = (typeof FinalizationRegistry === 'undefined')
268292
? { register: () => {}, unregister: () => {} }
@@ -567,6 +591,34 @@ export class WasmVM {
567591
var len1 = WASM_VECTOR_LEN;
568592
wasm.wasmvm_notify_error(this.__wbg_ptr, ptr0, len0, ptr1, len1);
569593
}
594+
/**
595+
* @param {string} error_message
596+
* @param {string | null | undefined} stacktrace
597+
* @param {WasmCommandType} wasm_command_type
598+
*/
599+
notify_error_for_next_command(error_message, stacktrace, wasm_command_type) {
600+
const ptr0 = passStringToWasm0(error_message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
601+
const len0 = WASM_VECTOR_LEN;
602+
var ptr1 = isLikeNone(stacktrace) ? 0 : passStringToWasm0(stacktrace, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
603+
var len1 = WASM_VECTOR_LEN;
604+
wasm.wasmvm_notify_error_for_next_command(this.__wbg_ptr, ptr0, len0, ptr1, len1, wasm_command_type);
605+
}
606+
/**
607+
* @param {string} error_message
608+
* @param {string | null | undefined} stacktrace
609+
* @param {WasmCommandType} wasm_command_type
610+
* @param {number} command_index
611+
* @param {string | null} [command_name]
612+
*/
613+
notify_error_for_specific_command(error_message, stacktrace, wasm_command_type, command_index, command_name) {
614+
const ptr0 = passStringToWasm0(error_message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
615+
const len0 = WASM_VECTOR_LEN;
616+
var ptr1 = isLikeNone(stacktrace) ? 0 : passStringToWasm0(stacktrace, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
617+
var len1 = WASM_VECTOR_LEN;
618+
var ptr2 = isLikeNone(command_name) ? 0 : passStringToWasm0(command_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
619+
var len2 = WASM_VECTOR_LEN;
620+
wasm.wasmvm_notify_error_for_specific_command(this.__wbg_ptr, ptr0, len0, ptr1, len1, wasm_command_type, command_index, ptr2, len2);
621+
}
570622
/**
571623
* @returns {any}
572624
*/
@@ -906,14 +958,14 @@ export class WasmVM {
906958
* @param {string} error_message
907959
* @param {string | null | undefined} error_stacktrace
908960
* @param {bigint} attempt_duration
909-
* @param {WasmExponentialRetryConfig} config
961+
* @param {WasmExponentialRetryConfig | null} [config]
910962
*/
911963
propose_run_completion_failure_transient(handle, error_message, error_stacktrace, attempt_duration, config) {
912964
const ptr0 = passStringToWasm0(error_message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
913965
const len0 = WASM_VECTOR_LEN;
914966
var ptr1 = isLikeNone(error_stacktrace) ? 0 : passStringToWasm0(error_stacktrace, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
915967
var len1 = WASM_VECTOR_LEN;
916-
const ret = wasm.wasmvm_propose_run_completion_failure_transient(this.__wbg_ptr, handle, ptr0, len0, ptr1, len1, attempt_duration, config);
968+
const ret = wasm.wasmvm_propose_run_completion_failure_transient(this.__wbg_ptr, handle, ptr0, len0, ptr1, len1, attempt_duration, isLikeNone(config) ? 0 : addToExternrefTable0(config));
917969
if (ret[1]) {
918970
throw takeFromExternrefTable0(ret[0]);
919971
}
@@ -962,6 +1014,13 @@ export class WasmVM {
9621014
const ret = wasm.wasmvm_is_processing(this.__wbg_ptr);
9631015
return ret !== 0;
9641016
}
1017+
/**
1018+
* @returns {number}
1019+
*/
1020+
last_command_index() {
1021+
const ret = wasm.wasmvm_last_command_index(this.__wbg_ptr);
1022+
return ret;
1023+
}
9651024
}
9661025

9671026
export function __wbg_String_eecc4a11987127d6(arg0, arg1) {
Binary file not shown.

packages/restate-sdk-cloudflare-workers/patches/vm/sdk_shared_core_wasm_bindings_bg.wasm.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export const wasmvm_get_response_head: (a: number) => number;
1919
export const wasmvm_notify_input: (a: number, b: number, c: number) => void;
2020
export const wasmvm_notify_input_closed: (a: number) => void;
2121
export const wasmvm_notify_error: (a: number, b: number, c: number, d: number, e: number) => void;
22+
export const wasmvm_notify_error_for_next_command: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
23+
export const wasmvm_notify_error_for_specific_command: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
2224
export const wasmvm_take_output: (a: number) => any;
2325
export const wasmvm_is_ready_to_execute: (a: number) => [number, number, number];
2426
export const wasmvm_is_completed: (a: number, b: number) => number;
@@ -45,12 +47,13 @@ export const wasmvm_sys_complete_promise_failure: (a: number, b: number, c: numb
4547
export const wasmvm_sys_run: (a: number, b: number, c: number) => [number, number, number];
4648
export const wasmvm_propose_run_completion_success: (a: number, b: number, c: number, d: number) => [number, number];
4749
export const wasmvm_propose_run_completion_failure: (a: number, b: number, c: any) => [number, number];
48-
export const wasmvm_propose_run_completion_failure_transient: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: any) => [number, number];
50+
export const wasmvm_propose_run_completion_failure_transient: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number) => [number, number];
4951
export const wasmvm_sys_cancel_invocation: (a: number, b: number, c: number) => [number, number];
5052
export const wasmvm_sys_write_output_success: (a: number, b: number, c: number) => [number, number];
5153
export const wasmvm_sys_write_output_failure: (a: number, b: any) => [number, number];
5254
export const wasmvm_sys_end: (a: number) => [number, number];
5355
export const wasmvm_is_processing: (a: number) => number;
56+
export const wasmvm_last_command_index: (a: number) => number;
5457
export const __wbg_wasmidentityverifier_free: (a: number, b: number) => void;
5558
export const wasmidentityverifier_new: (a: number, b: number) => [number, number, number];
5659
export const wasmidentityverifier_verify_identity: (a: number, b: number, c: number, d: number, e: number) => [number, number];

0 commit comments

Comments
 (0)