@cloudflare/sandbox 0.5.6 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile +54 -56
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -6
- package/.turbo/turbo-build.log +0 -23
- package/CHANGELOG.md +0 -463
- package/src/clients/base-client.ts +0 -356
- package/src/clients/command-client.ts +0 -133
- package/src/clients/file-client.ts +0 -300
- package/src/clients/git-client.ts +0 -98
- package/src/clients/index.ts +0 -64
- package/src/clients/interpreter-client.ts +0 -339
- package/src/clients/port-client.ts +0 -105
- package/src/clients/process-client.ts +0 -198
- package/src/clients/sandbox-client.ts +0 -39
- package/src/clients/types.ts +0 -88
- package/src/clients/utility-client.ts +0 -156
- package/src/errors/adapter.ts +0 -238
- package/src/errors/classes.ts +0 -594
- package/src/errors/index.ts +0 -109
- package/src/file-stream.ts +0 -175
- package/src/index.ts +0 -121
- package/src/interpreter.ts +0 -168
- package/src/openai/index.ts +0 -465
- package/src/request-handler.ts +0 -184
- package/src/sandbox.ts +0 -1937
- package/src/security.ts +0 -119
- package/src/sse-parser.ts +0 -147
- package/src/storage-mount/credential-detection.ts +0 -41
- package/src/storage-mount/errors.ts +0 -51
- package/src/storage-mount/index.ts +0 -17
- package/src/storage-mount/provider-detection.ts +0 -93
- package/src/storage-mount/types.ts +0 -17
- package/src/version.ts +0 -6
- package/tests/base-client.test.ts +0 -582
- package/tests/command-client.test.ts +0 -444
- package/tests/file-client.test.ts +0 -831
- package/tests/file-stream.test.ts +0 -310
- package/tests/get-sandbox.test.ts +0 -172
- package/tests/git-client.test.ts +0 -455
- package/tests/openai-shell-editor.test.ts +0 -434
- package/tests/port-client.test.ts +0 -283
- package/tests/process-client.test.ts +0 -649
- package/tests/request-handler.test.ts +0 -292
- package/tests/sandbox.test.ts +0 -890
- package/tests/sse-parser.test.ts +0 -291
- package/tests/storage-mount/credential-detection.test.ts +0 -119
- package/tests/storage-mount/provider-detection.test.ts +0 -77
- package/tests/utility-client.test.ts +0 -339
- package/tests/version.test.ts +0 -16
- package/tests/wrangler.jsonc +0 -35
- package/tsconfig.json +0 -11
- package/tsdown.config.ts +0 -13
- package/vitest.config.ts +0 -31
package/src/errors/classes.ts
DELETED
|
@@ -1,594 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe error classes that wrap ErrorResponse from container
|
|
3
|
-
*
|
|
4
|
-
* All error classes extend SandboxError<TContext> which wraps the full ErrorResponse
|
|
5
|
-
* and provides type-safe accessors for error properties.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type {
|
|
9
|
-
CodeExecutionContext,
|
|
10
|
-
CommandErrorContext,
|
|
11
|
-
CommandNotFoundContext,
|
|
12
|
-
ContextNotFoundContext,
|
|
13
|
-
ErrorResponse,
|
|
14
|
-
FileExistsContext,
|
|
15
|
-
FileNotFoundContext,
|
|
16
|
-
FileSystemContext,
|
|
17
|
-
GitAuthFailedContext,
|
|
18
|
-
GitBranchNotFoundContext,
|
|
19
|
-
GitErrorContext,
|
|
20
|
-
GitRepositoryNotFoundContext,
|
|
21
|
-
InternalErrorContext,
|
|
22
|
-
InterpreterNotReadyContext,
|
|
23
|
-
InvalidPortContext,
|
|
24
|
-
PortAlreadyExposedContext,
|
|
25
|
-
PortErrorContext,
|
|
26
|
-
PortNotExposedContext,
|
|
27
|
-
ProcessErrorContext,
|
|
28
|
-
ProcessNotFoundContext,
|
|
29
|
-
ValidationFailedContext
|
|
30
|
-
} from '@repo/shared/errors';
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Base SDK error that wraps ErrorResponse
|
|
34
|
-
* Preserves all error information from container
|
|
35
|
-
*/
|
|
36
|
-
export class SandboxError<TContext = Record<string, unknown>> extends Error {
|
|
37
|
-
constructor(public readonly errorResponse: ErrorResponse<TContext>) {
|
|
38
|
-
super(errorResponse.message);
|
|
39
|
-
this.name = 'SandboxError';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Convenience accessors
|
|
43
|
-
get code() {
|
|
44
|
-
return this.errorResponse.code;
|
|
45
|
-
}
|
|
46
|
-
get context() {
|
|
47
|
-
return this.errorResponse.context;
|
|
48
|
-
}
|
|
49
|
-
get httpStatus() {
|
|
50
|
-
return this.errorResponse.httpStatus;
|
|
51
|
-
}
|
|
52
|
-
get operation() {
|
|
53
|
-
return this.errorResponse.operation;
|
|
54
|
-
}
|
|
55
|
-
get suggestion() {
|
|
56
|
-
return this.errorResponse.suggestion;
|
|
57
|
-
}
|
|
58
|
-
get timestamp() {
|
|
59
|
-
return this.errorResponse.timestamp;
|
|
60
|
-
}
|
|
61
|
-
get documentation() {
|
|
62
|
-
return this.errorResponse.documentation;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Custom serialization for logging
|
|
66
|
-
toJSON() {
|
|
67
|
-
return {
|
|
68
|
-
name: this.name,
|
|
69
|
-
message: this.message,
|
|
70
|
-
code: this.code,
|
|
71
|
-
context: this.context,
|
|
72
|
-
httpStatus: this.httpStatus,
|
|
73
|
-
operation: this.operation,
|
|
74
|
-
suggestion: this.suggestion,
|
|
75
|
-
timestamp: this.timestamp,
|
|
76
|
-
documentation: this.documentation,
|
|
77
|
-
stack: this.stack
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// ============================================================================
|
|
83
|
-
// File System Errors
|
|
84
|
-
// ============================================================================
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Error thrown when a file or directory is not found
|
|
88
|
-
*/
|
|
89
|
-
export class FileNotFoundError extends SandboxError<FileNotFoundContext> {
|
|
90
|
-
constructor(errorResponse: ErrorResponse<FileNotFoundContext>) {
|
|
91
|
-
super(errorResponse);
|
|
92
|
-
this.name = 'FileNotFoundError';
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Type-safe accessors
|
|
96
|
-
get path() {
|
|
97
|
-
return this.context.path;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Error thrown when a file already exists
|
|
103
|
-
*/
|
|
104
|
-
export class FileExistsError extends SandboxError<FileExistsContext> {
|
|
105
|
-
constructor(errorResponse: ErrorResponse<FileExistsContext>) {
|
|
106
|
-
super(errorResponse);
|
|
107
|
-
this.name = 'FileExistsError';
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Type-safe accessor
|
|
111
|
-
get path() {
|
|
112
|
-
return this.context.path;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Generic file system error (permissions, disk full, etc.)
|
|
118
|
-
*/
|
|
119
|
-
export class FileSystemError extends SandboxError<FileSystemContext> {
|
|
120
|
-
constructor(errorResponse: ErrorResponse<FileSystemContext>) {
|
|
121
|
-
super(errorResponse);
|
|
122
|
-
this.name = 'FileSystemError';
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Type-safe accessors
|
|
126
|
-
get path() {
|
|
127
|
-
return this.context.path;
|
|
128
|
-
}
|
|
129
|
-
get stderr() {
|
|
130
|
-
return this.context.stderr;
|
|
131
|
-
}
|
|
132
|
-
get exitCode() {
|
|
133
|
-
return this.context.exitCode;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Error thrown when permission is denied
|
|
139
|
-
*/
|
|
140
|
-
export class PermissionDeniedError extends SandboxError<FileSystemContext> {
|
|
141
|
-
constructor(errorResponse: ErrorResponse<FileSystemContext>) {
|
|
142
|
-
super(errorResponse);
|
|
143
|
-
this.name = 'PermissionDeniedError';
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
get path() {
|
|
147
|
-
return this.context.path;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// ============================================================================
|
|
152
|
-
// Command Errors
|
|
153
|
-
// ============================================================================
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Error thrown when a command is not found
|
|
157
|
-
*/
|
|
158
|
-
export class CommandNotFoundError extends SandboxError<CommandNotFoundContext> {
|
|
159
|
-
constructor(errorResponse: ErrorResponse<CommandNotFoundContext>) {
|
|
160
|
-
super(errorResponse);
|
|
161
|
-
this.name = 'CommandNotFoundError';
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Type-safe accessor
|
|
165
|
-
get command() {
|
|
166
|
-
return this.context.command;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Generic command execution error
|
|
172
|
-
*/
|
|
173
|
-
export class CommandError extends SandboxError<CommandErrorContext> {
|
|
174
|
-
constructor(errorResponse: ErrorResponse<CommandErrorContext>) {
|
|
175
|
-
super(errorResponse);
|
|
176
|
-
this.name = 'CommandError';
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Type-safe accessors
|
|
180
|
-
get command() {
|
|
181
|
-
return this.context.command;
|
|
182
|
-
}
|
|
183
|
-
get exitCode() {
|
|
184
|
-
return this.context.exitCode;
|
|
185
|
-
}
|
|
186
|
-
get stdout() {
|
|
187
|
-
return this.context.stdout;
|
|
188
|
-
}
|
|
189
|
-
get stderr() {
|
|
190
|
-
return this.context.stderr;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// ============================================================================
|
|
195
|
-
// Process Errors
|
|
196
|
-
// ============================================================================
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Error thrown when a process is not found
|
|
200
|
-
*/
|
|
201
|
-
export class ProcessNotFoundError extends SandboxError<ProcessNotFoundContext> {
|
|
202
|
-
constructor(errorResponse: ErrorResponse<ProcessNotFoundContext>) {
|
|
203
|
-
super(errorResponse);
|
|
204
|
-
this.name = 'ProcessNotFoundError';
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Type-safe accessor
|
|
208
|
-
get processId() {
|
|
209
|
-
return this.context.processId;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Generic process error
|
|
215
|
-
*/
|
|
216
|
-
export class ProcessError extends SandboxError<ProcessErrorContext> {
|
|
217
|
-
constructor(errorResponse: ErrorResponse<ProcessErrorContext>) {
|
|
218
|
-
super(errorResponse);
|
|
219
|
-
this.name = 'ProcessError';
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// Type-safe accessors
|
|
223
|
-
get processId() {
|
|
224
|
-
return this.context.processId;
|
|
225
|
-
}
|
|
226
|
-
get pid() {
|
|
227
|
-
return this.context.pid;
|
|
228
|
-
}
|
|
229
|
-
get exitCode() {
|
|
230
|
-
return this.context.exitCode;
|
|
231
|
-
}
|
|
232
|
-
get stderr() {
|
|
233
|
-
return this.context.stderr;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// ============================================================================
|
|
238
|
-
// Port Errors
|
|
239
|
-
// ============================================================================
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Error thrown when a port is already exposed
|
|
243
|
-
*/
|
|
244
|
-
export class PortAlreadyExposedError extends SandboxError<PortAlreadyExposedContext> {
|
|
245
|
-
constructor(errorResponse: ErrorResponse<PortAlreadyExposedContext>) {
|
|
246
|
-
super(errorResponse);
|
|
247
|
-
this.name = 'PortAlreadyExposedError';
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Type-safe accessors
|
|
251
|
-
get port() {
|
|
252
|
-
return this.context.port;
|
|
253
|
-
}
|
|
254
|
-
get portName() {
|
|
255
|
-
return this.context.portName;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Error thrown when a port is not exposed
|
|
261
|
-
*/
|
|
262
|
-
export class PortNotExposedError extends SandboxError<PortNotExposedContext> {
|
|
263
|
-
constructor(errorResponse: ErrorResponse<PortNotExposedContext>) {
|
|
264
|
-
super(errorResponse);
|
|
265
|
-
this.name = 'PortNotExposedError';
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// Type-safe accessor
|
|
269
|
-
get port() {
|
|
270
|
-
return this.context.port;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Error thrown when a port number is invalid
|
|
276
|
-
*/
|
|
277
|
-
export class InvalidPortError extends SandboxError<InvalidPortContext> {
|
|
278
|
-
constructor(errorResponse: ErrorResponse<InvalidPortContext>) {
|
|
279
|
-
super(errorResponse);
|
|
280
|
-
this.name = 'InvalidPortError';
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// Type-safe accessors
|
|
284
|
-
get port() {
|
|
285
|
-
return this.context.port;
|
|
286
|
-
}
|
|
287
|
-
get reason() {
|
|
288
|
-
return this.context.reason;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Error thrown when a service on a port is not responding
|
|
294
|
-
*/
|
|
295
|
-
export class ServiceNotRespondingError extends SandboxError<PortErrorContext> {
|
|
296
|
-
constructor(errorResponse: ErrorResponse<PortErrorContext>) {
|
|
297
|
-
super(errorResponse);
|
|
298
|
-
this.name = 'ServiceNotRespondingError';
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// Type-safe accessors
|
|
302
|
-
get port() {
|
|
303
|
-
return this.context.port;
|
|
304
|
-
}
|
|
305
|
-
get portName() {
|
|
306
|
-
return this.context.portName;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Error thrown when a port is already in use
|
|
312
|
-
*/
|
|
313
|
-
export class PortInUseError extends SandboxError<PortErrorContext> {
|
|
314
|
-
constructor(errorResponse: ErrorResponse<PortErrorContext>) {
|
|
315
|
-
super(errorResponse);
|
|
316
|
-
this.name = 'PortInUseError';
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// Type-safe accessor
|
|
320
|
-
get port() {
|
|
321
|
-
return this.context.port;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Generic port operation error
|
|
327
|
-
*/
|
|
328
|
-
export class PortError extends SandboxError<PortErrorContext> {
|
|
329
|
-
constructor(errorResponse: ErrorResponse<PortErrorContext>) {
|
|
330
|
-
super(errorResponse);
|
|
331
|
-
this.name = 'PortError';
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// Type-safe accessors
|
|
335
|
-
get port() {
|
|
336
|
-
return this.context.port;
|
|
337
|
-
}
|
|
338
|
-
get portName() {
|
|
339
|
-
return this.context.portName;
|
|
340
|
-
}
|
|
341
|
-
get stderr() {
|
|
342
|
-
return this.context.stderr;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Error thrown when port exposure requires a custom domain
|
|
348
|
-
*/
|
|
349
|
-
export class CustomDomainRequiredError extends SandboxError<InternalErrorContext> {
|
|
350
|
-
constructor(errorResponse: ErrorResponse<InternalErrorContext>) {
|
|
351
|
-
super(errorResponse);
|
|
352
|
-
this.name = 'CustomDomainRequiredError';
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
// ============================================================================
|
|
357
|
-
// Git Errors
|
|
358
|
-
// ============================================================================
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Error thrown when a git repository is not found
|
|
362
|
-
*/
|
|
363
|
-
export class GitRepositoryNotFoundError extends SandboxError<GitRepositoryNotFoundContext> {
|
|
364
|
-
constructor(errorResponse: ErrorResponse<GitRepositoryNotFoundContext>) {
|
|
365
|
-
super(errorResponse);
|
|
366
|
-
this.name = 'GitRepositoryNotFoundError';
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// Type-safe accessor
|
|
370
|
-
get repository() {
|
|
371
|
-
return this.context.repository;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Error thrown when git authentication fails
|
|
377
|
-
*/
|
|
378
|
-
export class GitAuthenticationError extends SandboxError<GitAuthFailedContext> {
|
|
379
|
-
constructor(errorResponse: ErrorResponse<GitAuthFailedContext>) {
|
|
380
|
-
super(errorResponse);
|
|
381
|
-
this.name = 'GitAuthenticationError';
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// Type-safe accessor
|
|
385
|
-
get repository() {
|
|
386
|
-
return this.context.repository;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Error thrown when a git branch is not found
|
|
392
|
-
*/
|
|
393
|
-
export class GitBranchNotFoundError extends SandboxError<GitBranchNotFoundContext> {
|
|
394
|
-
constructor(errorResponse: ErrorResponse<GitBranchNotFoundContext>) {
|
|
395
|
-
super(errorResponse);
|
|
396
|
-
this.name = 'GitBranchNotFoundError';
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
// Type-safe accessors
|
|
400
|
-
get branch() {
|
|
401
|
-
return this.context.branch;
|
|
402
|
-
}
|
|
403
|
-
get repository() {
|
|
404
|
-
return this.context.repository;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
* Error thrown when a git network operation fails
|
|
410
|
-
*/
|
|
411
|
-
export class GitNetworkError extends SandboxError<GitErrorContext> {
|
|
412
|
-
constructor(errorResponse: ErrorResponse<GitErrorContext>) {
|
|
413
|
-
super(errorResponse);
|
|
414
|
-
this.name = 'GitNetworkError';
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// Type-safe accessors
|
|
418
|
-
get repository() {
|
|
419
|
-
return this.context.repository;
|
|
420
|
-
}
|
|
421
|
-
get branch() {
|
|
422
|
-
return this.context.branch;
|
|
423
|
-
}
|
|
424
|
-
get targetDir() {
|
|
425
|
-
return this.context.targetDir;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* Error thrown when git clone fails
|
|
431
|
-
*/
|
|
432
|
-
export class GitCloneError extends SandboxError<GitErrorContext> {
|
|
433
|
-
constructor(errorResponse: ErrorResponse<GitErrorContext>) {
|
|
434
|
-
super(errorResponse);
|
|
435
|
-
this.name = 'GitCloneError';
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
// Type-safe accessors
|
|
439
|
-
get repository() {
|
|
440
|
-
return this.context.repository;
|
|
441
|
-
}
|
|
442
|
-
get targetDir() {
|
|
443
|
-
return this.context.targetDir;
|
|
444
|
-
}
|
|
445
|
-
get stderr() {
|
|
446
|
-
return this.context.stderr;
|
|
447
|
-
}
|
|
448
|
-
get exitCode() {
|
|
449
|
-
return this.context.exitCode;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* Error thrown when git checkout fails
|
|
455
|
-
*/
|
|
456
|
-
export class GitCheckoutError extends SandboxError<GitErrorContext> {
|
|
457
|
-
constructor(errorResponse: ErrorResponse<GitErrorContext>) {
|
|
458
|
-
super(errorResponse);
|
|
459
|
-
this.name = 'GitCheckoutError';
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// Type-safe accessors
|
|
463
|
-
get branch() {
|
|
464
|
-
return this.context.branch;
|
|
465
|
-
}
|
|
466
|
-
get repository() {
|
|
467
|
-
return this.context.repository;
|
|
468
|
-
}
|
|
469
|
-
get stderr() {
|
|
470
|
-
return this.context.stderr;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* Error thrown when a git URL is invalid
|
|
476
|
-
*/
|
|
477
|
-
export class InvalidGitUrlError extends SandboxError<ValidationFailedContext> {
|
|
478
|
-
constructor(errorResponse: ErrorResponse<ValidationFailedContext>) {
|
|
479
|
-
super(errorResponse);
|
|
480
|
-
this.name = 'InvalidGitUrlError';
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// Type-safe accessor
|
|
484
|
-
get validationErrors() {
|
|
485
|
-
return this.context.validationErrors;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Generic git operation error
|
|
491
|
-
*/
|
|
492
|
-
export class GitError extends SandboxError<GitErrorContext> {
|
|
493
|
-
constructor(errorResponse: ErrorResponse<GitErrorContext>) {
|
|
494
|
-
super(errorResponse);
|
|
495
|
-
this.name = 'GitError';
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
// Type-safe accessors
|
|
499
|
-
get repository() {
|
|
500
|
-
return this.context.repository;
|
|
501
|
-
}
|
|
502
|
-
get branch() {
|
|
503
|
-
return this.context.branch;
|
|
504
|
-
}
|
|
505
|
-
get targetDir() {
|
|
506
|
-
return this.context.targetDir;
|
|
507
|
-
}
|
|
508
|
-
get stderr() {
|
|
509
|
-
return this.context.stderr;
|
|
510
|
-
}
|
|
511
|
-
get exitCode() {
|
|
512
|
-
return this.context.exitCode;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// ============================================================================
|
|
517
|
-
// Code Interpreter Errors
|
|
518
|
-
// ============================================================================
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* Error thrown when interpreter is not ready
|
|
522
|
-
*/
|
|
523
|
-
export class InterpreterNotReadyError extends SandboxError<InterpreterNotReadyContext> {
|
|
524
|
-
constructor(errorResponse: ErrorResponse<InterpreterNotReadyContext>) {
|
|
525
|
-
super(errorResponse);
|
|
526
|
-
this.name = 'InterpreterNotReadyError';
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
// Type-safe accessors
|
|
530
|
-
get retryAfter() {
|
|
531
|
-
return this.context.retryAfter;
|
|
532
|
-
}
|
|
533
|
-
get progress() {
|
|
534
|
-
return this.context.progress;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* Error thrown when a context is not found
|
|
540
|
-
*/
|
|
541
|
-
export class ContextNotFoundError extends SandboxError<ContextNotFoundContext> {
|
|
542
|
-
constructor(errorResponse: ErrorResponse<ContextNotFoundContext>) {
|
|
543
|
-
super(errorResponse);
|
|
544
|
-
this.name = 'ContextNotFoundError';
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
// Type-safe accessor
|
|
548
|
-
get contextId() {
|
|
549
|
-
return this.context.contextId;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* Error thrown when code execution fails
|
|
555
|
-
*/
|
|
556
|
-
export class CodeExecutionError extends SandboxError<CodeExecutionContext> {
|
|
557
|
-
constructor(errorResponse: ErrorResponse<CodeExecutionContext>) {
|
|
558
|
-
super(errorResponse);
|
|
559
|
-
this.name = 'CodeExecutionError';
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
// Type-safe accessors
|
|
563
|
-
get contextId() {
|
|
564
|
-
return this.context.contextId;
|
|
565
|
-
}
|
|
566
|
-
get ename() {
|
|
567
|
-
return this.context.ename;
|
|
568
|
-
}
|
|
569
|
-
get evalue() {
|
|
570
|
-
return this.context.evalue;
|
|
571
|
-
}
|
|
572
|
-
get traceback() {
|
|
573
|
-
return this.context.traceback;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// ============================================================================
|
|
578
|
-
// Validation Errors
|
|
579
|
-
// ============================================================================
|
|
580
|
-
|
|
581
|
-
/**
|
|
582
|
-
* Error thrown when validation fails
|
|
583
|
-
*/
|
|
584
|
-
export class ValidationFailedError extends SandboxError<ValidationFailedContext> {
|
|
585
|
-
constructor(errorResponse: ErrorResponse<ValidationFailedContext>) {
|
|
586
|
-
super(errorResponse);
|
|
587
|
-
this.name = 'ValidationFailedError';
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
// Type-safe accessor
|
|
591
|
-
get validationErrors() {
|
|
592
|
-
return this.context.validationErrors;
|
|
593
|
-
}
|
|
594
|
-
}
|
package/src/errors/index.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SDK Error System
|
|
3
|
-
*
|
|
4
|
-
* This module provides type-safe error classes that wrap ErrorResponse from the container.
|
|
5
|
-
* All error classes provide:
|
|
6
|
-
* - Type-safe accessors for error context
|
|
7
|
-
* - instanceof checks for error handling
|
|
8
|
-
* - Full ErrorResponse preservation via errorResponse property
|
|
9
|
-
* - Custom toJSON() for logging
|
|
10
|
-
*
|
|
11
|
-
* @example Basic error handling
|
|
12
|
-
* ```typescript
|
|
13
|
-
* import { FileNotFoundError } from './errors';
|
|
14
|
-
*
|
|
15
|
-
* try {
|
|
16
|
-
* await sandbox.file.read('/missing.txt');
|
|
17
|
-
* } catch (error) {
|
|
18
|
-
* if (error instanceof FileNotFoundError) {
|
|
19
|
-
* console.log(error.path); // Type-safe! string
|
|
20
|
-
* console.log(error.operation); // Type-safe! OperationType
|
|
21
|
-
* console.log(error.code); // "FILE_NOT_FOUND"
|
|
22
|
-
* console.log(error.suggestion); // Helpful message
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @example Error serialization
|
|
28
|
-
* ```typescript
|
|
29
|
-
* try {
|
|
30
|
-
* await sandbox.file.read('/missing.txt');
|
|
31
|
-
* } catch (error) {
|
|
32
|
-
* // Full context available
|
|
33
|
-
* console.log(error.errorResponse);
|
|
34
|
-
*
|
|
35
|
-
* // Pretty-prints with custom toJSON
|
|
36
|
-
* console.log(JSON.stringify(error, null, 2));
|
|
37
|
-
* }
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
// Re-export context types for advanced usage
|
|
42
|
-
export type {
|
|
43
|
-
CodeExecutionContext,
|
|
44
|
-
CommandErrorContext,
|
|
45
|
-
CommandNotFoundContext,
|
|
46
|
-
ContextNotFoundContext,
|
|
47
|
-
ErrorCodeType,
|
|
48
|
-
ErrorResponse,
|
|
49
|
-
FileExistsContext,
|
|
50
|
-
FileNotFoundContext,
|
|
51
|
-
FileSystemContext,
|
|
52
|
-
GitAuthFailedContext,
|
|
53
|
-
GitBranchNotFoundContext,
|
|
54
|
-
GitErrorContext,
|
|
55
|
-
GitRepositoryNotFoundContext,
|
|
56
|
-
InternalErrorContext,
|
|
57
|
-
InterpreterNotReadyContext,
|
|
58
|
-
InvalidPortContext,
|
|
59
|
-
OperationType,
|
|
60
|
-
PortAlreadyExposedContext,
|
|
61
|
-
PortErrorContext,
|
|
62
|
-
PortNotExposedContext,
|
|
63
|
-
ProcessErrorContext,
|
|
64
|
-
ProcessNotFoundContext,
|
|
65
|
-
ValidationFailedContext
|
|
66
|
-
} from '@repo/shared/errors';
|
|
67
|
-
// Re-export shared types and constants
|
|
68
|
-
export { ErrorCode, Operation } from '@repo/shared/errors';
|
|
69
|
-
|
|
70
|
-
// Export adapter function
|
|
71
|
-
export { createErrorFromResponse } from './adapter';
|
|
72
|
-
// Export all error classes
|
|
73
|
-
export {
|
|
74
|
-
CodeExecutionError,
|
|
75
|
-
CommandError,
|
|
76
|
-
// Command Errors
|
|
77
|
-
CommandNotFoundError,
|
|
78
|
-
ContextNotFoundError,
|
|
79
|
-
CustomDomainRequiredError,
|
|
80
|
-
FileExistsError,
|
|
81
|
-
// File System Errors
|
|
82
|
-
FileNotFoundError,
|
|
83
|
-
FileSystemError,
|
|
84
|
-
GitAuthenticationError,
|
|
85
|
-
GitBranchNotFoundError,
|
|
86
|
-
GitCheckoutError,
|
|
87
|
-
GitCloneError,
|
|
88
|
-
GitError,
|
|
89
|
-
GitNetworkError,
|
|
90
|
-
// Git Errors
|
|
91
|
-
GitRepositoryNotFoundError,
|
|
92
|
-
// Code Interpreter Errors
|
|
93
|
-
InterpreterNotReadyError,
|
|
94
|
-
InvalidGitUrlError,
|
|
95
|
-
InvalidPortError,
|
|
96
|
-
PermissionDeniedError,
|
|
97
|
-
// Port Errors
|
|
98
|
-
PortAlreadyExposedError,
|
|
99
|
-
PortError,
|
|
100
|
-
PortInUseError,
|
|
101
|
-
PortNotExposedError,
|
|
102
|
-
ProcessError,
|
|
103
|
-
// Process Errors
|
|
104
|
-
ProcessNotFoundError,
|
|
105
|
-
SandboxError,
|
|
106
|
-
ServiceNotRespondingError,
|
|
107
|
-
// Validation Errors
|
|
108
|
-
ValidationFailedError
|
|
109
|
-
} from './classes';
|