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

39 lines
981 B
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;
};
export class PiProcessError extends Error {
readonly code: PiProcessErrorCode;
readonly generation?: number;
readonly diagnostic?: string;
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;
}
}
export function isPiProcessError(error: unknown): error is PiProcessError {
return error instanceof PiProcessError;
}