Skip to content
54 changes: 54 additions & 0 deletions packages/sandbox/src/errors/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import type {
PortErrorContext,
PortNotExposedContext,
ProcessErrorContext,
ProcessExitedBeforeReadyContext,
ProcessNotFoundContext,
ProcessReadyTimeoutContext,
ValidationFailedContext
} from '@repo/shared/errors';

Expand Down Expand Up @@ -592,3 +594,55 @@ export class ValidationFailedError extends SandboxError<ValidationFailedContext>
return this.context.validationErrors;
}
}

// ============================================================================
// Process Readiness Errors
// ============================================================================

/**
* Error thrown when a process does not become ready within the timeout period
*/
export class ProcessReadyTimeoutError extends SandboxError<ProcessReadyTimeoutContext> {
constructor(errorResponse: ErrorResponse<ProcessReadyTimeoutContext>) {
super(errorResponse);
this.name = 'ProcessReadyTimeoutError';
}

// Type-safe accessors
get processId() {
return this.context.processId;
}
get command() {
return this.context.command;
}
get condition() {
return this.context.condition;
}
get timeout() {
return this.context.timeout;
}
}

/**
* Error thrown when a process exits before becoming ready
*/
export class ProcessExitedBeforeReadyError extends SandboxError<ProcessExitedBeforeReadyContext> {
constructor(errorResponse: ErrorResponse<ProcessExitedBeforeReadyContext>) {
super(errorResponse);
this.name = 'ProcessExitedBeforeReadyError';
}

// Type-safe accessors
get processId() {
return this.context.processId;
}
get command() {
return this.context.command;
}
get condition() {
return this.context.condition;
}
get exitCode() {
return this.context.exitCode;
}
}
5 changes: 5 additions & 0 deletions packages/sandbox/src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export type {
PortErrorContext,
PortNotExposedContext,
ProcessErrorContext,
ProcessExitedBeforeReadyContext,
ProcessNotFoundContext,
ProcessReadyTimeoutContext,
ValidationFailedContext
} from '@repo/shared/errors';
// Re-export shared types and constants
Expand Down Expand Up @@ -100,8 +102,11 @@ export {
PortInUseError,
PortNotExposedError,
ProcessError,
// Process Readiness Errors
ProcessExitedBeforeReadyError,
// Process Errors
ProcessNotFoundError,
ProcessReadyTimeoutError,
SandboxError,
ServiceNotRespondingError,
// Validation Errors
Expand Down
13 changes: 12 additions & 1 deletion packages/sandbox/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export type {
RunCodeOptions,
SandboxOptions,
SessionOptions,
StreamOptions
StreamOptions,
// Process readiness types
WaitForLogResult
} from '@repo/shared';
// Export type guards for runtime validation
export { isExecResult, isProcess, isProcessStatus } from '@repo/shared';
Expand Down Expand Up @@ -96,6 +98,15 @@ export type {
ExecutionCallbacks,
InterpreterClient
} from './clients/interpreter-client.js';
export type {
ProcessExitedBeforeReadyContext,
ProcessReadyTimeoutContext
} from './errors';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do end users need these?

// Export process readiness errors
export {
ProcessExitedBeforeReadyError,
ProcessReadyTimeoutError
} from './errors';
// Export file streaming utilities for binary file support
export { collectFile, streamFile } from './file-stream';
// Export interpreter functionality
Expand Down
Loading
Loading