1
- // TODO(aduh95): use errors exported by the internal/errors module
2
- /* eslint-disable no-restricted-syntax */
3
-
4
1
'use strict' ;
5
2
6
3
const {
7
4
ArrayPrototypePush,
8
- Error,
9
5
ErrorCaptureStackTrace,
10
6
FunctionPrototypeBind,
11
7
JSONParse,
@@ -15,6 +11,7 @@ const {
15
11
} = primordials ;
16
12
17
13
const Buffer = require ( 'buffer' ) . Buffer ;
14
+ const { ERR_DEBUGGER_ERROR } = require ( 'internal/errors' ) . codes ;
18
15
const { EventEmitter } = require ( 'events' ) ;
19
16
const http = require ( 'http' ) ;
20
17
const URL = require ( 'url' ) ;
@@ -39,7 +36,7 @@ const kEightBytePayloadLengthField = 127;
39
36
const kMaskingKeyWidthInBytes = 4 ;
40
37
41
38
function unpackError ( { code, message, data } ) {
42
- const err = new Error ( `${ message } - ${ data } ` ) ;
39
+ const err = new ERR_DEBUGGER_ERROR ( `${ message } - ${ data } ` ) ;
43
40
err . code = code ;
44
41
ErrorCaptureStackTrace ( err , unpackError ) ;
45
42
return err ;
@@ -101,14 +98,14 @@ function decodeFrameHybi17(data) {
101
98
const masked = ( secondByte & kMaskBit ) !== 0 ;
102
99
const compressed = reserved1 ;
103
100
if ( compressed ) {
104
- throw new Error ( 'Compressed frames not supported' ) ;
101
+ throw new ERR_DEBUGGER_ERROR ( 'Compressed frames not supported' ) ;
105
102
}
106
103
if ( ! final || reserved2 || reserved3 ) {
107
- throw new Error ( 'Only compression extension is supported' ) ;
104
+ throw new ERR_DEBUGGER_ERROR ( 'Only compression extension is supported' ) ;
108
105
}
109
106
110
107
if ( masked ) {
111
- throw new Error ( 'Masked server frame - not supported' ) ;
108
+ throw new ERR_DEBUGGER_ERROR ( 'Masked server frame - not supported' ) ;
112
109
}
113
110
114
111
let closed = false ;
@@ -119,7 +116,7 @@ function decodeFrameHybi17(data) {
119
116
case kOpCodeText :
120
117
break ;
121
118
default :
122
- throw new Error ( `Unsupported op code ${ opCode } ` ) ;
119
+ throw new ERR_DEBUGGER_ERROR ( `Unsupported op code ${ opCode } ` ) ;
123
120
}
124
121
125
122
let payloadLength = secondByte & kPayloadLengthMask ;
@@ -183,7 +180,9 @@ class Client extends EventEmitter {
183
180
debuglog ( '< %s' , payloadStr ) ;
184
181
const lastChar = payloadStr [ payloadStr . length - 1 ] ;
185
182
if ( payloadStr [ 0 ] !== '{' || lastChar !== '}' ) {
186
- throw new Error ( `Payload does not look like JSON: ${ payloadStr } ` ) ;
183
+ throw new ERR_DEBUGGER_ERROR (
184
+ `Payload does not look like JSON: ${ payloadStr } `
185
+ ) ;
187
186
}
188
187
let payload ;
189
188
try {
@@ -204,7 +203,7 @@ class Client extends EventEmitter {
204
203
this . emit ( 'debugEvent' , method , params ) ;
205
204
this . emit ( method , params ) ;
206
205
} else {
207
- throw new Error ( `Unsupported response: ${ payloadStr } ` ) ;
206
+ throw new ERR_DEBUGGER_ERROR ( `Unsupported response: ${ payloadStr } ` ) ;
208
207
}
209
208
}
210
209
}
@@ -226,7 +225,7 @@ class Client extends EventEmitter {
226
225
callMethod ( method , params ) {
227
226
return new Promise ( ( resolve , reject ) => {
228
227
if ( ! this . _socket ) {
229
- reject ( new Error ( 'Use `run` to start the app again.' ) ) ;
228
+ reject ( new ERR_DEBUGGER_ERROR ( 'Use `run` to start the app again.' ) ) ;
230
229
return ;
231
230
}
232
231
const data = { id : ++ this . _lastId , method, params } ;
@@ -254,14 +253,17 @@ class Client extends EventEmitter {
254
253
function parseChunks ( ) {
255
254
const resBody = Buffer . concat ( chunks ) . toString ( ) ;
256
255
if ( httpRes . statusCode !== 200 ) {
257
- reject ( new Error ( `Unexpected ${ httpRes . statusCode } : ${ resBody } ` ) ) ;
256
+ reject ( new ERR_DEBUGGER_ERROR (
257
+ `Unexpected ${ httpRes . statusCode } : ${ resBody } `
258
+ ) ) ;
258
259
return ;
259
260
}
260
261
try {
261
262
resolve ( JSONParse ( resBody ) ) ;
262
263
} catch {
263
- reject ( new Error ( `Response didn't contain JSON: ${ resBody } ` ) ) ;
264
-
264
+ reject ( new ERR_DEBUGGER_ERROR (
265
+ `Response didn't contain JSON: ${ resBody } `
266
+ ) ) ;
265
267
}
266
268
}
267
269
0 commit comments