From 99cb640f910ccc7cded5c86c7dd13f94c7efcf66 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 13 Jun 2021 05:53:05 -0700 Subject: [PATCH] debugger: use ERR_DEBUGGER_STARTUP_ERROR in _inspect.js PR-URL: https://github.com/nodejs/node/pull/39024 Backport-PR-URL: https://github.com/nodejs/node/pull/39446 Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca Reviewed-By: Jan Krems --- lib/internal/inspector/_inspect.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/internal/inspector/_inspect.js b/lib/internal/inspector/_inspect.js index 4786a478fe14d8..526545d3abc761 100644 --- a/lib/internal/inspector/_inspect.js +++ b/lib/internal/inspector/_inspect.js @@ -8,7 +8,6 @@ const { ArrayPrototypePop, ArrayPrototypeShift, ArrayPrototypeSlice, - Error, FunctionPrototypeBind, Number, Promise, @@ -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. @@ -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) => { @@ -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);