Skip to content
Open
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
12 changes: 11 additions & 1 deletion packages/libs/restate-sdk/src/context_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
this.coreVm.propose_run_completion_failure(handle, {
code: err.code,
message: err.message,
metadata: [],
metadata: Object.entries(err.metadata ?? {}).map(
([key, value]) => ({ key, value })
),
});
} else if (err instanceof RetryableError) {
const maxRetryDuration =
Expand Down Expand Up @@ -1023,9 +1025,17 @@ function SuccessWithSerde<T>(

const Failure: Completer = (value, prom) => {
if (typeof value === "object" && "Failure" in value) {
const metadata = (value.Failure.metadata ?? []).reduce(
(acc: Record<string, string>, { key, value: v }: { key: string; value: string }) => {
acc[key] = v;
return acc;
},
{} as Record<string, string>
);
prom.reject(
new TerminalError(value.Failure.message, {
errorCode: value.Failure.code,
metadata,
})
);
return Promise.resolve(true);
Expand Down
4 changes: 3 additions & 1 deletion packages/libs/restate-sdk/src/endpoint/handlers/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ export class GenericHandler implements RestateHandler {
coreVm.sys_write_output_failure({
code: error.code,
message: error.message,
metadata: [],
metadata: Object.entries(error.metadata ?? {}).map(
([key, value]) => ({ key, value })
),
});
coreVm.sys_end();
return;
Expand Down
7 changes: 7 additions & 0 deletions packages/libs/restate-sdk/src/types/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class RestateError extends Error {
*/
export class TerminalError extends RestateError {
public override name = "TerminalError";
public readonly metadata: Record<string, string>;

constructor(
message: string,
Expand All @@ -104,9 +105,15 @@ export class TerminalError extends RestateError {
* @deprecated YOU MUST NOT USE THIS FIELD, AS IT WON'T BE RECORDED AND CAN LEAD TO NON-DETERMINISM! From the next SDK version, the constructor won't accept this field anymore.
*/
cause?: any;
/**
* Metadata key-value pairs to attach to the terminal error.
* These are propagated through the Restate protocol (requires service protocol v6+).
*/
metadata?: Record<string, string>;
}
) {
super(message, options);
this.metadata = options?.metadata ?? {};
}
}

Expand Down