Skip to content

Commit a3991d7

Browse files
Trottrichardlau
authored andcommitted
debugger: use ERR_DEBUGGER_ERROR in debugger client
PR-URL: #39024 Backport-PR-URL: #39446 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Jan Krems <[email protected]>
1 parent cfccf13 commit a3991d7

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

lib/internal/inspector/inspect_client.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
// TODO(aduh95): use errors exported by the internal/errors module
2-
/* eslint-disable no-restricted-syntax */
3-
41
'use strict';
52

63
const {
74
ArrayPrototypePush,
8-
Error,
95
ErrorCaptureStackTrace,
106
FunctionPrototypeBind,
117
JSONParse,
@@ -15,6 +11,7 @@ const {
1511
} = primordials;
1612

1713
const Buffer = require('buffer').Buffer;
14+
const { ERR_DEBUGGER_ERROR } = require('internal/errors').codes;
1815
const { EventEmitter } = require('events');
1916
const http = require('http');
2017
const URL = require('url');
@@ -39,7 +36,7 @@ const kEightBytePayloadLengthField = 127;
3936
const kMaskingKeyWidthInBytes = 4;
4037

4138
function unpackError({ code, message, data }) {
42-
const err = new Error(`${message} - ${data}`);
39+
const err = new ERR_DEBUGGER_ERROR(`${message} - ${data}`);
4340
err.code = code;
4441
ErrorCaptureStackTrace(err, unpackError);
4542
return err;
@@ -101,14 +98,14 @@ function decodeFrameHybi17(data) {
10198
const masked = (secondByte & kMaskBit) !== 0;
10299
const compressed = reserved1;
103100
if (compressed) {
104-
throw new Error('Compressed frames not supported');
101+
throw new ERR_DEBUGGER_ERROR('Compressed frames not supported');
105102
}
106103
if (!final || reserved2 || reserved3) {
107-
throw new Error('Only compression extension is supported');
104+
throw new ERR_DEBUGGER_ERROR('Only compression extension is supported');
108105
}
109106

110107
if (masked) {
111-
throw new Error('Masked server frame - not supported');
108+
throw new ERR_DEBUGGER_ERROR('Masked server frame - not supported');
112109
}
113110

114111
let closed = false;
@@ -119,7 +116,7 @@ function decodeFrameHybi17(data) {
119116
case kOpCodeText:
120117
break;
121118
default:
122-
throw new Error(`Unsupported op code ${opCode}`);
119+
throw new ERR_DEBUGGER_ERROR(`Unsupported op code ${opCode}`);
123120
}
124121

125122
let payloadLength = secondByte & kPayloadLengthMask;
@@ -183,7 +180,9 @@ class Client extends EventEmitter {
183180
debuglog('< %s', payloadStr);
184181
const lastChar = payloadStr[payloadStr.length - 1];
185182
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+
);
187186
}
188187
let payload;
189188
try {
@@ -204,7 +203,7 @@ class Client extends EventEmitter {
204203
this.emit('debugEvent', method, params);
205204
this.emit(method, params);
206205
} else {
207-
throw new Error(`Unsupported response: ${payloadStr}`);
206+
throw new ERR_DEBUGGER_ERROR(`Unsupported response: ${payloadStr}`);
208207
}
209208
}
210209
}
@@ -226,7 +225,7 @@ class Client extends EventEmitter {
226225
callMethod(method, params) {
227226
return new Promise((resolve, reject) => {
228227
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.'));
230229
return;
231230
}
232231
const data = { id: ++this._lastId, method, params };
@@ -254,14 +253,17 @@ class Client extends EventEmitter {
254253
function parseChunks() {
255254
const resBody = Buffer.concat(chunks).toString();
256255
if (httpRes.statusCode !== 200) {
257-
reject(new Error(`Unexpected ${httpRes.statusCode}: ${resBody}`));
256+
reject(new ERR_DEBUGGER_ERROR(
257+
`Unexpected ${httpRes.statusCode}: ${resBody}`
258+
));
258259
return;
259260
}
260261
try {
261262
resolve(JSONParse(resBody));
262263
} 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+
));
265267
}
266268
}
267269

0 commit comments

Comments
 (0)