Skip to content

Improve errors, propagating the error code #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,26 @@ export function __wbindgen_error_new(arg0, arg1) {
return addHeapObject(ret);
};

export function __wbindgen_jsval_loose_eq(arg0, arg1) {
const ret = getObject(arg0) == getObject(arg1);
return ret;
};

export function __wbindgen_boolean_get(arg0) {
const v = getObject(arg0);
const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
return ret;
};

export function __wbindgen_string_new(arg0, arg1) {
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};

export function __wbg_set_f975102236d3c502(arg0, arg1, arg2) {
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
};

export function __wbg_new_abda76e883ba8a5f() {
const ret = new Error();
return addHeapObject(ret);
Expand All @@ -1334,17 +1354,6 @@ export function __wbg_error_f851667af71bcfc6(arg0, arg1) {
}
};

export function __wbindgen_jsval_loose_eq(arg0, arg1) {
const ret = getObject(arg0) == getObject(arg1);
return ret;
};

export function __wbindgen_boolean_get(arg0) {
const v = getObject(arg0);
const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
return ret;
};

export function __wbg_String_88810dfeb4021902(arg0, arg1) {
const ret = String(getObject(arg1));
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
Expand All @@ -1353,11 +1362,6 @@ export function __wbg_String_88810dfeb4021902(arg0, arg1) {
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
};

export function __wbindgen_string_new(arg0, arg1) {
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};

export function __wbg_getwithrefkey_5e6d9547403deab8(arg0, arg1) {
const ret = getObject(arg0)[getObject(arg1)];
return addHeapObject(ret);
Expand Down
Binary file not shown.
12 changes: 10 additions & 2 deletions packages/restate-sdk/src/context_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import type * as vm from "./endpoint/handlers/vm/sdk_shared_core_wasm_bindings.j
import {
ensureError,
INTERNAL_ERROR_CODE,
RestateError,
SUSPENDED_ERROR_CODE,
TerminalError,
TimeoutError,
UNKNOWN_ERROR_CODE,
Expand Down Expand Up @@ -803,8 +805,14 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
}

handleInvocationEndError(e: unknown) {
const err = ensureError(e);
this.coreVm.notify_error(err.message, err.stack);
const error = ensureError(e);
if (
!(error instanceof RestateError) ||
error.code != SUSPENDED_ERROR_CODE
) {
this.console.warn("Function completed with an error.\n", error);
}
this.coreVm.notify_error(error.message, error.stack);

// From now on, no progress will be made.
this.invocationEndPromise.resolve();
Expand Down
14 changes: 12 additions & 2 deletions packages/restate-sdk/src/endpoint/handlers/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
*/

import { ensureError, TerminalError } from "../../types/errors.js";
import {
ensureError,
RestateError,
SUSPENDED_ERROR_CODE,
TerminalError,
} from "../../types/errors.js";
import type { ProtocolMode } from "../../types/discovery.js";
import type { ComponentHandler } from "../../types/components.js";
import { parseUrlComponents } from "../../types/components.js";
Expand Down Expand Up @@ -311,7 +316,12 @@ export class GenericHandler implements RestateHandler {
})
.catch((e) => {
const error = ensureError(e);
console.warn("Function completed with an error.\n", error);
if (
!(error instanceof RestateError) ||
error.code != SUSPENDED_ERROR_CODE
) {
console.warn("Function completed with an error.\n", error);
}

if (error instanceof TerminalError) {
coreVm.sys_write_output_failure({
Expand Down

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions packages/restate-sdk/src/types/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ export const INTERNAL_ERROR_CODE = 500;
export const TIMEOUT_ERROR_CODE = 408;
export const UNKNOWN_ERROR_CODE = 500;

// From shared core!
export const SUSPENDED_ERROR_CODE = 599;

export function ensureError(e: unknown): Error {
if (e instanceof Error) {
return e;
}
if (typeof e == "object" && e != null && "code" in e && "message" in e) {
// This is an error from the VM
return new RestateError(e.message as string, {
errorCode: e.code as number,
});
}

let msg;
try {
Expand Down
Loading