mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
debugger: use ERR_DEBUGGER_ERROR in debugger client
PR-URL: https://github.com/nodejs/node/pull/39024 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com>
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
// TODO(aduh95): use errors exported by the internal/errors module
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
ArrayPrototypePush,
|
||||
Error,
|
||||
ErrorCaptureStackTrace,
|
||||
FunctionPrototypeBind,
|
||||
JSONParse,
|
||||
@@ -15,6 +11,7 @@ const {
|
||||
} = primordials;
|
||||
|
||||
const Buffer = require('buffer').Buffer;
|
||||
const { ERR_DEBUGGER_ERROR } = require('internal/errors').codes;
|
||||
const { EventEmitter } = require('events');
|
||||
const http = require('http');
|
||||
const URL = require('url');
|
||||
@@ -39,7 +36,7 @@ const kEightBytePayloadLengthField = 127;
|
||||
const kMaskingKeyWidthInBytes = 4;
|
||||
|
||||
function unpackError({ code, message, data }) {
|
||||
const err = new Error(`${message} - ${data}`);
|
||||
const err = new ERR_DEBUGGER_ERROR(`${message} - ${data}`);
|
||||
err.code = code;
|
||||
ErrorCaptureStackTrace(err, unpackError);
|
||||
return err;
|
||||
@@ -101,14 +98,14 @@ function decodeFrameHybi17(data) {
|
||||
const masked = (secondByte & kMaskBit) !== 0;
|
||||
const compressed = reserved1;
|
||||
if (compressed) {
|
||||
throw new Error('Compressed frames not supported');
|
||||
throw new ERR_DEBUGGER_ERROR('Compressed frames not supported');
|
||||
}
|
||||
if (!final || reserved2 || reserved3) {
|
||||
throw new Error('Only compression extension is supported');
|
||||
throw new ERR_DEBUGGER_ERROR('Only compression extension is supported');
|
||||
}
|
||||
|
||||
if (masked) {
|
||||
throw new Error('Masked server frame - not supported');
|
||||
throw new ERR_DEBUGGER_ERROR('Masked server frame - not supported');
|
||||
}
|
||||
|
||||
let closed = false;
|
||||
@@ -119,7 +116,7 @@ function decodeFrameHybi17(data) {
|
||||
case kOpCodeText:
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported op code ${opCode}`);
|
||||
throw new ERR_DEBUGGER_ERROR(`Unsupported op code ${opCode}`);
|
||||
}
|
||||
|
||||
let payloadLength = secondByte & kPayloadLengthMask;
|
||||
@@ -183,7 +180,7 @@ class Client extends EventEmitter {
|
||||
debuglog('< %s', payloadStr);
|
||||
const lastChar = payloadStr[payloadStr.length - 1];
|
||||
if (payloadStr[0] !== '{' || lastChar !== '}') {
|
||||
throw new Error(`Payload does not look like JSON: ${payloadStr}`);
|
||||
throw new ERR_DEBUGGER_ERROR(`Payload does not look like JSON: ${payloadStr}`);
|
||||
}
|
||||
let payload;
|
||||
try {
|
||||
@@ -204,7 +201,7 @@ class Client extends EventEmitter {
|
||||
this.emit('debugEvent', method, params);
|
||||
this.emit(method, params);
|
||||
} else {
|
||||
throw new Error(`Unsupported response: ${payloadStr}`);
|
||||
throw new ERR_DEBUGGER_ERROR(`Unsupported response: ${payloadStr}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,7 +223,7 @@ class Client extends EventEmitter {
|
||||
callMethod(method, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this._socket) {
|
||||
reject(new Error('Use `run` to start the app again.'));
|
||||
reject(new ERR_DEBUGGER_ERROR('Use `run` to start the app again.'));
|
||||
return;
|
||||
}
|
||||
const data = { id: ++this._lastId, method, params };
|
||||
@@ -254,13 +251,13 @@ class Client extends EventEmitter {
|
||||
function parseChunks() {
|
||||
const resBody = Buffer.concat(chunks).toString();
|
||||
if (httpRes.statusCode !== 200) {
|
||||
reject(new Error(`Unexpected ${httpRes.statusCode}: ${resBody}`));
|
||||
reject(new ERR_DEBUGGER_ERROR(`Unexpected ${httpRes.statusCode}: ${resBody}`));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
resolve(JSONParse(resBody));
|
||||
} catch {
|
||||
reject(new Error(`Response didn't contain JSON: ${resBody}`));
|
||||
reject(new ERR_DEBUGGER_ERROR(`Response didn't contain JSON: ${resBody}`));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user