Skip to content

Commit cd8f327

Browse files
committed
The --debug parameter now automatically breaks in the debugger when InternalError is thrown
1 parent a0c10ac commit cd8f327

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

apps/api-extractor/src/cli/ApiExtractorCommandLine.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as colors from 'colors';
55
import * as os from 'os';
66

77
import { CommandLineParser, CommandLineFlagParameter } from '@microsoft/ts-command-line';
8+
import { InternalError } from '@microsoft/node-core-library';
9+
810
import { RunAction } from './RunAction';
911

1012
export class ApiExtractorCommandLine extends CommandLineParser {
@@ -27,6 +29,10 @@ export class ApiExtractorCommandLine extends CommandLineParser {
2729
}
2830

2931
protected onExecute(): Promise<void> { // override
32+
if (this._debugParameter.value) {
33+
InternalError.breakInDebugger = true;
34+
}
35+
3036
return super.onExecute().catch((error) => {
3137

3238
if (this._debugParameter.value) {

apps/rush-lib/src/cli/RushCommandLineParser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as os from 'os';
66
import * as path from 'path';
77

88
import { CommandLineParser, CommandLineFlagParameter, CommandLineAction } from '@microsoft/ts-command-line';
9+
import { InternalError } from '@microsoft/node-core-library';
910

1011
import { RushConfiguration } from '../api/RushConfiguration';
1112
import { RushConstants } from '../logic/RushConstants';
@@ -81,6 +82,10 @@ export class RushCommandLineParser extends CommandLineParser {
8182
// -- if it falsely appears to succeed, we could merge bad PRs, publish empty packages, etc.
8283
process.exitCode = 1;
8384

85+
if (this._debugParameter.value) {
86+
InternalError.breakInDebugger = true;
87+
}
88+
8489
return this._wrapOnExecute().catch((error: Error) => {
8590
this._reportErrorAndSetExitCode(error);
8691
}).then(() => {

common/reviews/api/node-core-library.api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ interface IJsonSchemaValidateOptions {
217217
// @public
218218
class InternalError extends Error {
219219
constructor(message: string);
220+
static breakInDebugger: boolean;
220221
// @override (undocumented)
221222
toString(): string;
222223
readonly unformattedMessage: string;

libraries/node-core-library/src/InternalError.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
* @public
1212
*/
1313
export class InternalError extends Error {
14+
/**
15+
* If true, a JavScript `debugger;` statement will be invoked whenever the `InternalError` constructor is called.
16+
*
17+
* @remarks
18+
* Generally applications should not be catching and ignoring an `InternalError`. Instead, the error should
19+
* be reported and typically the application will terminate. Thus, if `InternalError` is constructed, it's
20+
* almost always something we want to examine in a debugger.
21+
*/
22+
public static breakInDebugger: boolean = true;
23+
1424
/**
1525
* The underlying error message, without the additional boilerplate for an `InternalError`.
1626
*/
@@ -39,6 +49,10 @@ export class InternalError extends Error {
3949
(this as any).__proto__ = InternalError.prototype; // tslint:disable-line:no-any
4050

4151
this.unformattedMessage = message;
52+
53+
if (InternalError.breakInDebugger) {
54+
debugger; // tslint:disable-line:no-debugger
55+
}
4256
}
4357

4458
/** @override */

0 commit comments

Comments
 (0)