Skip to content

Commit dc92181

Browse files
Trottdanielleadams
authored andcommitted
debugger: use ERR_DEBUGGER_ERROR in debugger client
PR-URL: #39024 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Jan Krems <[email protected]>
1 parent 631856e commit dc92181

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

lib/internal/inspector/inspect_client.js

Lines changed: 11 additions & 14 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,7 @@ 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(`Payload does not look like JSON: ${payloadStr}`);
187184
}
188185
let payload;
189186
try {
@@ -204,7 +201,7 @@ class Client extends EventEmitter {
204201
this.emit('debugEvent', method, params);
205202
this.emit(method, params);
206203
} else {
207-
throw new Error(`Unsupported response: ${payloadStr}`);
204+
throw new ERR_DEBUGGER_ERROR(`Unsupported response: ${payloadStr}`);
208205
}
209206
}
210207
}
@@ -226,7 +223,7 @@ class Client extends EventEmitter {
226223
callMethod(method, params) {
227224
return new Promise((resolve, reject) => {
228225
if (!this._socket) {
229-
reject(new Error('Use `run` to start the app again.'));
226+
reject(new ERR_DEBUGGER_ERROR('Use `run` to start the app again.'));
230227
return;
231228
}
232229
const data = { id: ++this._lastId, method, params };
@@ -254,13 +251,13 @@ class Client extends EventEmitter {
254251
function parseChunks() {
255252
const resBody = Buffer.concat(chunks).toString();
256253
if (httpRes.statusCode !== 200) {
257-
reject(new Error(`Unexpected ${httpRes.statusCode}: ${resBody}`));
254+
reject(new ERR_DEBUGGER_ERROR(`Unexpected ${httpRes.statusCode}: ${resBody}`));
258255
return;
259256
}
260257
try {
261258
resolve(JSONParse(resBody));
262259
} catch {
263-
reject(new Error(`Response didn't contain JSON: ${resBody}`));
260+
reject(new ERR_DEBUGGER_ERROR(`Response didn't contain JSON: ${resBody}`));
264261

265262
}
266263
}

0 commit comments

Comments
 (0)