Skip to content

Commit

Permalink
debugger: use ERR_DEBUGGER_STARTUP_ERROR in _inspect.js
Browse files Browse the repository at this point in the history
PR-URL: #39024
Backport-PR-URL: #39446
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
  • Loading branch information
Trott authored and richardlau committed Jul 22, 2021
1 parent 9b993ed commit b7ee9d8
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/internal/inspector/_inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {
ArrayPrototypePop,
ArrayPrototypeShift,
ArrayPrototypeSlice,
Error,
FunctionPrototypeBind,
Number,
Promise,
Expand Down Expand Up @@ -50,12 +49,7 @@ const { 0: InspectClient, 1: createRepl } =

const debuglog = util.debuglog('inspect');

class StartupError extends Error {
constructor(message) {
super(message);
this.name = 'StartupError';
}
}
const { ERR_DEBUGGER_STARTUP_ERROR } = require('internal/errors').codes;

async function portIsFree(host, port, timeout = 9999) {
if (port === 0) return; // Binding to a random port.
Expand All @@ -70,7 +64,7 @@ async function portIsFree(host, port, timeout = 9999) {
while (true) {
await asyncIterator.next();
if (signal.aborted) {
throw new StartupError( // eslint-disable-line no-restricted-syntax
throw new ERR_DEBUGGER_STARTUP_ERROR(
`Timeout (${timeout}) waiting for ${host}:${port} to be free`);
}
const error = await new Promise((resolve) => {
Expand Down Expand Up @@ -346,7 +340,7 @@ function startInspect(argv = ArrayPrototypeSlice(process.argv, 2),
stdin.resume();

function handleUnexpectedError(e) {
if (!(e instanceof StartupError)) {
if (e.code !== 'ERR_DEBUGGER_STARTUP_ERROR') {
console.error('There was an internal error in Node.js. ' +
'Please report this bug.');
console.error(e.message);
Expand Down

0 comments on commit b7ee9d8

Please sign in to comment.