Skip to content

Commit 136eaca

Browse files
committed
PR feedback
1 parent 7ce60b6 commit 136eaca

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ interface IJsonSchemaValidateOptions {
228228
// @public
229229
class InternalError extends Error {
230230
constructor(message: string);
231+
// @override (undocumented)
232+
toString(): string;
233+
readonly unformattedMessage: string;
231234
}
232235

233236
// @public

common/reviews/api/stream-collator.api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @public
22
class Interleaver {
3-
constructor();
43
static registerTask(taskName: string, quietMode?: boolean): ITaskWriter;
54
static reset(): void;
65
static setStdOut(stdout: {

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,47 @@
22
// See LICENSE in the project root for license information.
33

44
/**
5-
* An `Error` subclass that should be thrown to report an unexpected state, which may indicate a software bug.
6-
* The application may handle this error by instructing the user to report the problem to the application maintainers.
5+
* An `Error` subclass that should be thrown to report an unexpected state that may indicate a software defect.
6+
* An application may handle this error by instructing the end user to report an issue to the application maintainers.
7+
*
8+
* @remarks
9+
* Do not use this class unless you intend to solicit bug reports from end users.
710
*
811
* @public
912
*/
1013
export class InternalError extends Error {
14+
/**
15+
* The underlying error message, without the additional boilerplate for an `InternalError`.
16+
*/
17+
public readonly unformattedMessage: string;
18+
19+
private static _formatMessage(unformattedMessage: string): string {
20+
return `Internal Error: ${unformattedMessage}\n\nYou have encountered a software defect. Please consider`
21+
+ `reporting the issue to the maintainers of this application.`;
22+
}
23+
24+
/**
25+
* Constructs a new instance of the {@link InternalError} class.
26+
*
27+
* @param message - A message describing the error. This will be assigned to
28+
* {@link InternalError.unformattedMessage}. The `Error.message` field will have additional boilerplate
29+
* explaining that the user has encountered a software defect.
30+
*/
1131
constructor(message: string) {
12-
super('Internal Error: ' + message);
32+
super(InternalError._formatMessage(message));
1333

1434
// Manually set the prototype, as we can no longer extend built-in classes like Error, Array, Map, etc.
1535
// tslint:disable-next-line:max-line-length
1636
// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
1737
//
1838
// Note: the prototype must also be set on any classes which extend this one
1939
(this as any).__proto__ = InternalError.prototype; // tslint:disable-line:no-any
40+
41+
this.unformattedMessage = message;
42+
}
43+
44+
/** @override */
45+
public toString(): string {
46+
return this.message; // Avoid adding the "Error:" prefix
2047
}
2148
}

0 commit comments

Comments
 (0)