Skip to content

Commit

Permalink
debugger: use error codes in debugger REPL
Browse files Browse the repository at this point in the history
PR-URL: nodejs#39024
Backport-PR-URL: nodejs#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 foxxyz committed Oct 18, 2021
1 parent 753e2be commit 3b1ab39
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/internal/inspector/inspect_repl.js
@@ -1,5 +1,5 @@
// TODO(trott): enable ESLint
/* eslint-disable getter-return, no-restricted-syntax */
/* eslint-disable getter-return */

'use strict';

Expand All @@ -18,7 +18,6 @@ const {
ArrayPrototypeSome,
ArrayPrototypeSplice,
Date,
Error,
FunctionPrototypeCall,
JSONStringify,
MathMax,
Expand Down Expand Up @@ -47,9 +46,12 @@ const {
StringPrototypeStartsWith,
StringPrototypeToUpperCase,
StringPrototypeTrim,
TypeError,
} = primordials;

const { ERR_DEBUGGER_ERROR } = require('internal/errors').codes;

const { validateString } = require('internal/validators');

const FS = require('fs');
const Path = require('path');
const Repl = require('repl');
Expand Down Expand Up @@ -176,7 +178,7 @@ function extractErrorMessage(stack) {

function convertResultToError(result) {
const { className, description } = result;
const err = new Error(extractErrorMessage(description));
const err = new ERR_DEBUGGER_ERROR(extractErrorMessage(description));
err.stack = description;
ObjectDefineProperty(err, 'name', { value: className });
return err;
Expand Down Expand Up @@ -357,7 +359,7 @@ function createRepl(inspector) {

function getCurrentLocation() {
if (!selectedFrame) {
throw new Error('Requires execution to be paused');
throw new ERR_DEBUGGER_ERROR('Requires execution to be paused');
}
return selectedFrame.location;
}
Expand Down Expand Up @@ -543,7 +545,7 @@ function createRepl(inspector) {
// Repl asked for scope variables
if (code === '.scope') {
if (!selectedFrame) {
throw new Error('Requires execution to be paused');
throw new ERR_DEBUGGER_ERROR('Requires execution to be paused');
}
const scopes = await selectedFrame.loadScopes();
return ArrayPrototypeMap(scopes, (scope) => scope.completionGroup);
Expand Down Expand Up @@ -706,9 +708,7 @@ function createRepl(inspector) {
registerBreakpoint);
}

if (typeof script !== 'string') {
throw new TypeError(`setBreakpoint() expects a string, got ${script}`);
}
validateString(script, 'script');

// setBreakpoint('fn()'): Break when a function is called
if (StringPrototypeEndsWith(script, '()')) {
Expand Down

0 comments on commit 3b1ab39

Please sign in to comment.