-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
errors.ts
226 lines (197 loc) · 6.14 KB
/
errors.ts
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import { isNullOrUndefined } from './utils';
export class StateError extends Error {
constructor(
public wantedStates: string[],
public gotState: string
) {
super(
`Incorrect State for operation: "${gotState}", allowed States: "[${wantedStates.join(
','
)}]"\n` +
'This may be because of using a v6.x way of calling functions, look at the following guide if anything applies:\n' +
'https://nodkz.github.io/mongodb-memory-server/docs/guides/migration/migrate7#no-function-other-than-start-create-ensureinstance-will-be-starting-anything'
);
}
}
export class UnknownLockfileStatusError extends Error {
constructor(public status: number) {
super(`Unknown LockFile Status: "${status}"`);
}
}
export class UnableToUnlockLockfileError extends Error {
constructor(
public thisInstance: boolean,
public file: string
) {
super(
`Cannot unlock file "${file}", because it is not locked by this ${
thisInstance ? 'instance' : 'process'
}`
);
}
}
export class UnknownPlatformError extends Error {
constructor(public platform: string) {
super(`Unknown Platform: "${platform}"`);
}
}
export class UnknownArchitectureError extends Error {
constructor(
public arch: string,
public platform?: string
) {
super();
if (!isNullOrUndefined(platform)) {
this.message = `Unsupported Architecture-Platform combination: arch: "${arch}", platform: "${platform}"`;
} else {
this.message = `Unsupported Architecture: "${arch}"`;
}
}
}
export class WaitForPrimaryTimeoutError extends Error {
constructor(
public timeout: number,
public where?: string
) {
super(`Timed out after ${timeout}ms while waiting for a Primary (where: "${where}")`);
}
}
export class Md5CheckFailedError extends Error {
constructor(
public binarymd5: string,
public checkfilemd5: string
) {
super(`MD5 check failed! Binary MD5 is "${binarymd5}", Checkfile MD5 is "${checkfilemd5}"`);
}
}
export class StartBinaryFailedError extends Error {
constructor(public binary: string) {
super(`Starting the Binary Failed (PID is undefined)! Binary: "${binary}"`);
}
}
export class InstanceInfoError extends Error {
constructor(public where: string) {
super(`"instanceInfo" was undefined when expected to be defined! (where: "${where}")`);
}
}
export class KeyFileMissingError extends Error {
constructor() {
super(`"keyfileLocation" was undefined when expected!`);
}
}
export class AuthNotObjectError extends Error {
constructor() {
super('"auth" was not a object when it was expected!');
}
}
export class InsufficientPermissionsError extends Error {
constructor(public path: string) {
super(`File "${path}" does not have the required Permissions, required Permissions: "--x"`);
}
}
export class BinaryNotFoundError extends Error {
constructor(
public path: string,
public extra: string = ''
) {
super(`No Binary at path "${path}" was found! (ENOENT)${extra}`);
}
}
/**
* Custom Fallback Error for "utils.assertion", it is a named/custom Error to confuse less in the stacktrace
*/
export class AssertionFallbackError extends Error {
constructor() {
super('Assert failed - no custom error');
}
}
export class ReplsetCountLowError extends Error {
constructor(public count: number) {
super(`ReplSet Count needs to be 1 or higher! (specified count: "${count}")`);
}
}
export class ParseArchiveRegexError extends Error {
constructor(public key: string) {
super(`Expected "${key}" to be found in regex groups`);
}
}
export class NoRegexMatchError extends Error {
constructor(
public name: string,
public extra?: string
) {
super();
const addExtra = !!extra ? `(${extra})` : '';
this.message = `Expected "${name}" to have Regex Matches${addExtra}`;
}
}
export class KnownVersionIncompatibilityError extends Error {
constructor(
public dist: string,
public requested_version: string,
public available_versions: string,
public extra?: string
) {
super();
const addExtra = !!extra ? `\n${extra}` : '';
this.message = `Requested Version "${requested_version}" is not available for "${dist}"! Available Versions: "${available_versions}"${addExtra}`;
}
}
/**
* Basic Error wrapper for "instanceError" events from "stdoutHandler"
*/
export class StdoutInstanceError extends Error {
// not using "public variable: type", because it is a basic wrapper for "Error"
constructor(msg: string) {
super(msg);
}
}
/**
* Error for when the instance closes with non-0 (or non-12) codes or signals
*/
export class UnexpectedCloseError extends Error {
constructor(code: number | null, signal: string | null) {
super();
this.message = `Instance closed unexpectedly with code "${code}" and signal "${signal}"`;
if (signal == 'SIGILL') {
this.message +=
'\nThe Process Exited with SIGILL, which mean illegal instruction, which is commonly thrown in mongodb 5.0+ when not having AVX available on the CPU';
}
if (process.platform === 'win32' && (code ?? 0) > 1000000000) {
this.message +=
'\nExit Code is large, commonly meaning that vc_redist is not installed, the latest vc_redist can be found at https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170';
}
}
}
/**
* Error for when VERSION fails to coerce to a semver version but is required
*/
export class UnknownVersionError extends Error {
constructor(public version: string) {
super(`Could not coerce VERSION to a semver version (version: "${version}")`);
}
}
/**
* Error for when downloading fails
*/
export class DownloadError extends Error {
constructor(
public url: string,
public msg: string
) {
super(`Download failed for url \"${url}\", Details:\n${msg}`);
}
}
/**
* Error for when the linux distro is unknown
*/
export class UnknownLinuxDistro extends Error {
constructor(
public distro: string,
public id_like: string[]
) {
super(`Unknown/unsupported linux "${distro}" id_like's: [${id_like?.join(', ')}]`);
}
}
/* Custom Generic Error class for MMS */
export class GenericMMSError extends Error {}