Skip to content

Commit 415c66d

Browse files
authored
fix: make error symbols non enumerable (#4531)
1 parent f182ff1 commit 415c66d

File tree

2 files changed

+72
-24
lines changed

2 files changed

+72
-24
lines changed

lib/core/errors.js

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class UndiciError extends Error {
1212
return instance && instance[kUndiciError] === true
1313
}
1414

15-
[kUndiciError] = true
15+
get [kUndiciError] () {
16+
return true
17+
}
1618
}
1719

1820
const kConnectTimeoutError = Symbol.for('undici.error.UND_ERR_CONNECT_TIMEOUT')
@@ -28,7 +30,9 @@ class ConnectTimeoutError extends UndiciError {
2830
return instance && instance[kConnectTimeoutError] === true
2931
}
3032

31-
[kConnectTimeoutError] = true
33+
get [kConnectTimeoutError] () {
34+
return true
35+
}
3236
}
3337

3438
const kHeadersTimeoutError = Symbol.for('undici.error.UND_ERR_HEADERS_TIMEOUT')
@@ -44,7 +48,9 @@ class HeadersTimeoutError extends UndiciError {
4448
return instance && instance[kHeadersTimeoutError] === true
4549
}
4650

47-
[kHeadersTimeoutError] = true
51+
get [kHeadersTimeoutError] () {
52+
return true
53+
}
4854
}
4955

5056
const kHeadersOverflowError = Symbol.for('undici.error.UND_ERR_HEADERS_OVERFLOW')
@@ -60,7 +66,9 @@ class HeadersOverflowError extends UndiciError {
6066
return instance && instance[kHeadersOverflowError] === true
6167
}
6268

63-
[kHeadersOverflowError] = true
69+
get [kHeadersOverflowError] () {
70+
return true
71+
}
6472
}
6573

6674
const kBodyTimeoutError = Symbol.for('undici.error.UND_ERR_BODY_TIMEOUT')
@@ -76,7 +84,9 @@ class BodyTimeoutError extends UndiciError {
7684
return instance && instance[kBodyTimeoutError] === true
7785
}
7886

79-
[kBodyTimeoutError] = true
87+
get [kBodyTimeoutError] () {
88+
return true
89+
}
8090
}
8191

8292
const kInvalidArgumentError = Symbol.for('undici.error.UND_ERR_INVALID_ARG')
@@ -92,7 +102,9 @@ class InvalidArgumentError extends UndiciError {
92102
return instance && instance[kInvalidArgumentError] === true
93103
}
94104

95-
[kInvalidArgumentError] = true
105+
get [kInvalidArgumentError] () {
106+
return true
107+
}
96108
}
97109

98110
const kInvalidReturnValueError = Symbol.for('undici.error.UND_ERR_INVALID_RETURN_VALUE')
@@ -108,7 +120,9 @@ class InvalidReturnValueError extends UndiciError {
108120
return instance && instance[kInvalidReturnValueError] === true
109121
}
110122

111-
[kInvalidReturnValueError] = true
123+
get [kInvalidReturnValueError] () {
124+
return true
125+
}
112126
}
113127

114128
const kAbortError = Symbol.for('undici.error.UND_ERR_ABORT')
@@ -124,7 +138,9 @@ class AbortError extends UndiciError {
124138
return instance && instance[kAbortError] === true
125139
}
126140

127-
[kAbortError] = true
141+
get [kAbortError] () {
142+
return true
143+
}
128144
}
129145

130146
const kRequestAbortedError = Symbol.for('undici.error.UND_ERR_ABORTED')
@@ -140,7 +156,9 @@ class RequestAbortedError extends AbortError {
140156
return instance && instance[kRequestAbortedError] === true
141157
}
142158

143-
[kRequestAbortedError] = true
159+
get [kRequestAbortedError] () {
160+
return true
161+
}
144162
}
145163

146164
const kInformationalError = Symbol.for('undici.error.UND_ERR_INFO')
@@ -156,7 +174,9 @@ class InformationalError extends UndiciError {
156174
return instance && instance[kInformationalError] === true
157175
}
158176

159-
[kInformationalError] = true
177+
get [kInformationalError] () {
178+
return true
179+
}
160180
}
161181

162182
const kRequestContentLengthMismatchError = Symbol.for('undici.error.UND_ERR_REQ_CONTENT_LENGTH_MISMATCH')
@@ -172,7 +192,9 @@ class RequestContentLengthMismatchError extends UndiciError {
172192
return instance && instance[kRequestContentLengthMismatchError] === true
173193
}
174194

175-
[kRequestContentLengthMismatchError] = true
195+
get [kRequestContentLengthMismatchError] () {
196+
return true
197+
}
176198
}
177199

178200
const kResponseContentLengthMismatchError = Symbol.for('undici.error.UND_ERR_RES_CONTENT_LENGTH_MISMATCH')
@@ -188,7 +210,9 @@ class ResponseContentLengthMismatchError extends UndiciError {
188210
return instance && instance[kResponseContentLengthMismatchError] === true
189211
}
190212

191-
[kResponseContentLengthMismatchError] = true
213+
get [kResponseContentLengthMismatchError] () {
214+
return true
215+
}
192216
}
193217

194218
const kClientDestroyedError = Symbol.for('undici.error.UND_ERR_DESTROYED')
@@ -204,7 +228,9 @@ class ClientDestroyedError extends UndiciError {
204228
return instance && instance[kClientDestroyedError] === true
205229
}
206230

207-
[kClientDestroyedError] = true
231+
get [kClientDestroyedError] () {
232+
return true
233+
}
208234
}
209235

210236
const kClientClosedError = Symbol.for('undici.error.UND_ERR_CLOSED')
@@ -220,7 +246,9 @@ class ClientClosedError extends UndiciError {
220246
return instance && instance[kClientClosedError] === true
221247
}
222248

223-
[kClientClosedError] = true
249+
get [kClientClosedError] () {
250+
return true
251+
}
224252
}
225253

226254
const kSocketError = Symbol.for('undici.error.UND_ERR_SOCKET')
@@ -237,7 +265,9 @@ class SocketError extends UndiciError {
237265
return instance && instance[kSocketError] === true
238266
}
239267

240-
[kSocketError] = true
268+
get [kSocketError] () {
269+
return true
270+
}
241271
}
242272

243273
const kNotSupportedError = Symbol.for('undici.error.UND_ERR_NOT_SUPPORTED')
@@ -253,7 +283,9 @@ class NotSupportedError extends UndiciError {
253283
return instance && instance[kNotSupportedError] === true
254284
}
255285

256-
[kNotSupportedError] = true
286+
get [kNotSupportedError] () {
287+
return true
288+
}
257289
}
258290

259291
const kBalancedPoolMissingUpstreamError = Symbol.for('undici.error.UND_ERR_BPL_MISSING_UPSTREAM')
@@ -269,7 +301,9 @@ class BalancedPoolMissingUpstreamError extends UndiciError {
269301
return instance && instance[kBalancedPoolMissingUpstreamError] === true
270302
}
271303

272-
[kBalancedPoolMissingUpstreamError] = true
304+
get [kBalancedPoolMissingUpstreamError] () {
305+
return true
306+
}
273307
}
274308

275309
const kHTTPParserError = Symbol.for('undici.error.UND_ERR_HTTP_PARSER')
@@ -285,7 +319,9 @@ class HTTPParserError extends Error {
285319
return instance && instance[kHTTPParserError] === true
286320
}
287321

288-
[kHTTPParserError] = true
322+
get [kHTTPParserError] () {
323+
return true
324+
}
289325
}
290326

291327
const kResponseExceededMaxSizeError = Symbol.for('undici.error.UND_ERR_RES_EXCEEDED_MAX_SIZE')
@@ -301,7 +337,9 @@ class ResponseExceededMaxSizeError extends UndiciError {
301337
return instance && instance[kResponseExceededMaxSizeError] === true
302338
}
303339

304-
[kResponseExceededMaxSizeError] = true
340+
get [kResponseExceededMaxSizeError] () {
341+
return true
342+
}
305343
}
306344

307345
const kRequestRetryError = Symbol.for('undici.error.UND_ERR_REQ_RETRY')
@@ -320,7 +358,9 @@ class RequestRetryError extends UndiciError {
320358
return instance && instance[kRequestRetryError] === true
321359
}
322360

323-
[kRequestRetryError] = true
361+
get [kRequestRetryError] () {
362+
return true
363+
}
324364
}
325365

326366
const kResponseError = Symbol.for('undici.error.UND_ERR_RESPONSE')
@@ -339,7 +379,9 @@ class ResponseError extends UndiciError {
339379
return instance && instance[kResponseError] === true
340380
}
341381

342-
[kResponseError] = true
382+
get [kResponseError] () {
383+
return true
384+
}
343385
}
344386

345387
const kSecureProxyConnectionError = Symbol.for('undici.error.UND_ERR_PRX_TLS')
@@ -356,7 +398,9 @@ class SecureProxyConnectionError extends UndiciError {
356398
return instance && instance[kSecureProxyConnectionError] === true
357399
}
358400

359-
[kSecureProxyConnectionError] = true
401+
get [kSecureProxyConnectionError] () {
402+
return true
403+
}
360404
}
361405

362406
const kMaxOriginsReachedError = Symbol.for('undici.error.UND_ERR_MAX_ORIGINS_REACHED')
@@ -372,7 +416,9 @@ class MaxOriginsReachedError extends UndiciError {
372416
return instance && instance[kMaxOriginsReachedError] === true
373417
}
374418

375-
[kMaxOriginsReachedError] = true
419+
get [kMaxOriginsReachedError] () {
420+
return true
421+
}
376422
}
377423

378424
module.exports = {

lib/mock/mock-errors.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class MockNotMatchedError extends UndiciError {
1919
return instance && instance[kMockNotMatchedError] === true
2020
}
2121

22-
[kMockNotMatchedError] = true
22+
get [kMockNotMatchedError] () {
23+
return true
24+
}
2325
}
2426

2527
module.exports = {

0 commit comments

Comments
 (0)