@comake/skl-js-engine
Version:
Standard Knowledge Language Javascript Engine
64 lines (57 loc) • 1.56 kB
text/typescript
/**
* Custom error classes for better error handling in JSExecutor
*/
/**
* Error thrown when code execution times out
*/
export class ExecutionTimeoutError extends Error {
public constructor(timeout: number) {
super(`Execution timed out after ${timeout}ms`);
this.name = 'ExecutionTimeoutError';
}
}
/**
* Error thrown when the Deno process fails to spawn
*/
export class ProcessSpawnError extends Error {
public constructor(originalError: Error) {
super(`Failed to spawn Deno process: ${originalError.message}`);
this.name = 'ProcessSpawnError';
}
}
/**
* Error thrown when the executor output cannot be parsed
*/
export class OutputParsingError extends Error {
public constructor(rawOutput: string, originalError: Error) {
super(`Failed to parse output: ${originalError.message}`);
this.name = 'OutputParsingError';
}
}
/**
* Error thrown when code execution fails in general
*/
export class CodeExecutionError extends Error {
public constructor(message: string) {
super(`Failed to execute code: ${message}`);
this.name = 'CodeExecutionError';
}
}
/**
* Error thrown when the JSExecutor is not initialized
*/
export class NotInitializedError extends Error {
public constructor(message: string) {
super(message);
this.name = 'NotInitializedError';
}
}
/**
* Error thrown when the JSExecutor is already initialized
*/
export class AlreadyInitializedError extends Error {
public constructor(message: string) {
super(message);
this.name = 'AlreadyInitializedError';
}
}