Add error handling logic

This commit is contained in:
Nilay Majorwar
2022-01-22 13:53:57 +05:30
parent d8481c097b
commit 0efd4c79ef
9 changed files with 291 additions and 131 deletions

View File

@@ -1,4 +1,5 @@
import { StepExecutionResult } from "./types";
import { DocumentRange, StepExecutionResult } from "./types";
import * as E from "./worker-errors";
/** Types of requests the worker handles */
export type WorkerRequestData =
@@ -39,7 +40,28 @@ export type WorkerAckType =
| "prepare" // on preparing for execution
| "pause"; // on pausing execution
/** Errors associated with each response ack type */
export type WorkerAckError = {
init: undefined;
reset: undefined;
"bp-update": undefined;
prepare: E.WorkerParseError;
pause: undefined;
};
/** Types of responses the worker can send */
export type WorkerResponseData<RS> =
| { type: "ack"; data: WorkerAckType }
| { type: "result"; data: StepExecutionResult<RS> };
export type WorkerResponseData<RS, A extends WorkerAckType> =
/** Ack for one-off requests, optionally containing error occured (if any) */
| {
type: "ack";
data: A;
error?: WorkerAckError[A];
}
/** Response containing step execution result, and runtime error (if any) */
| {
type: "result";
data: StepExecutionResult<RS>;
error?: E.WorkerRuntimeError;
}
/** Response indicating a bug in worker/engine logic */
| { type: "error"; error: Error };