-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy patherrors.ts
More file actions
134 lines (111 loc) · 3.32 KB
/
Copy patherrors.ts
File metadata and controls
134 lines (111 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// This will eventually contain all the error classes thrown by the engine
export class EngineError extends Error {
source = 'engine';
severity = '-'; // subclasses MUST provide this!
}
// This is thrown if a workflow takes too long to run
// It is generated by workerpool and thrown if the workerpool promise fails to resolve
export class TimeoutError extends EngineError {
severity = 'kill';
name = 'TimeoutError';
duration;
constructor(durationInMs: number) {
super();
this.duration = durationInMs;
if (durationInMs) {
this.message = `Workflow failed to return within ${durationInMs}ms`;
} else {
this.message = `Workflow failed to return within the specified time limit`;
}
}
}
// This is a catch-all error thrown during execution
export class ExecutionError extends EngineError {
severity = 'exception';
name = 'ExecutionError';
message;
original: any; // this is the original error
constructor(original: any) {
super();
this.original = original;
this.message = original.message;
this.stack = original.stack;
}
}
export class CompileError extends EngineError {
severity = 'crash'; // Syntax errors are crashes, but what if we get a module resolution thing?
type = 'CompileError';
subtype;
message;
jobId;
constructor(error: any, jobId: string) {
super();
this.jobId = jobId;
this.message = `${jobId}: ${error.message}`;
this.name = error.constructor.name ?? error.name ?? error.type;
// TODO remove?
this.subtype = error.type || error.constructor.name;
}
}
export class AutoinstallError extends EngineError {
severity = 'exception'; // Syntax errors are crashes, but what if we get a module resolution thing?
name = 'AutoinstallError';
message;
constructor(specifier: string, error: any) {
super();
this.message = `Error installing ${specifier}: ${error.message}`;
}
}
// Where an OOM kill came from:
// - 'heap' the V8 heap limit (thread resourceLimits or --max-old-space-size)
// - 'cgroup' the OS cgroup memory.max ceiling (kernel SIGKILL)
export type OOMSource = 'heap' | 'cgroup';
export class OOMError extends EngineError {
severity = 'kill';
name = 'OOMError';
message;
source: OOMSource;
constructor(source: OOMSource = 'heap') {
super();
this.source = source;
this.message = `Run exceeded maximum memory usage`;
}
}
export class ExitError extends EngineError {
severity = 'crash';
name = 'ExitError';
code;
message;
constructor(code: number) {
super();
this.code = code;
this.message = `Process exited with code: ${code}`;
// Remove the stack trace
// It contains no useful information
this.stack = '';
}
}
export type CredentialErrorObj = { id: string; step: string; error: string };
// Error lazy-loading a credenial
export class CredentialLoadError extends EngineError {
severity = 'exception';
name = 'CredentialLoadError';
message;
original: any; // this is the original error
constructor(errors: CredentialErrorObj[]) {
super();
const ids: Record<string, true> = {};
this.message = errors
.filter((e) => {
if (!ids[e.id]) {
ids[e.id] = true;
return true;
}
})
.map(
(e) =>
`Failed to load credential ${e.id}${e.error ? `: ${e.error}` : ''}`
)
.join('\n');
}
}