feat: add Pi process and RPC foundation
This commit is contained in:
38
electron/coding-runtime/pi/process-errors.ts
Normal file
38
electron/coding-runtime/pi/process-errors.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user