Files
makelore/electron/coding-runtime/pi/process-errors.ts

45 lines
1.2 KiB
TypeScript

export type PiProcessErrorCode =
| 'PI_RPC_PROTOCOL_ERROR'
| 'PI_RPC_TIMEOUT'
| 'PI_RPC_ABORTED'
| 'PI_RPC_RESPONSE_ERROR'
| 'PI_RPC_WRITE_FAILED'
| 'PI_RPC_EXITED'
| 'PI_WORKER_START_FAILED'
| 'PI_WORKER_STOPPED'
| 'PI_WORKER_STOP_FAILED';
export type PiProcessErrorDetails = {
cause?: unknown;
generation?: number;
diagnostic?: string;
exitCode?: number | null;
signal?: NodeJS.Signals | null;
};
export class PiProcessError extends Error {
readonly code: PiProcessErrorCode;
readonly generation?: number;
readonly diagnostic?: string;
readonly exitCode?: number | null;
readonly signal?: NodeJS.Signals | null;
constructor(
code: PiProcessErrorCode,
message: string,
details: PiProcessErrorDetails = {},
) {
super(message, details.cause === undefined ? undefined : { cause: details.cause });
this.name = 'PiProcessError';
this.code = code;
this.generation = details.generation;
this.diagnostic = details.diagnostic;
this.exitCode = details.exitCode;
this.signal = details.signal;
}
}
export function isPiProcessError(error: unknown): error is PiProcessError {
return error instanceof PiProcessError;
}