-
Notifications
You must be signed in to change notification settings - Fork 2
/
exception.ts
43 lines (38 loc) · 951 Bytes
/
exception.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import {red, yellow} from 'chalk';
export interface VSetExceptionParams {
message: string;
suggestion?: string;
file?: string;
line?: number;
}
export class VSetupException {
private readonly message: string;
private readonly suggestion: string | undefined;
/**
* @constructor
*
* @param {VSetExceptionParams} params The pappermintparameters contaning, messages, suggestion
* line and files
*/
constructor(params: VSetExceptionParams) {
this.message = params.message;
this.suggestion = params.suggestion;
}
/**
* @public
*
* Throw the exception
*
* @param {boolean} fatal Whether to exit from the program after the
* error or not
*/
public throwException(fatal: boolean) {
console.log(red(this.message));
if (this.suggestion) {
console.log(yellow(this.suggestion));
}
if (fatal) {
process.exit();
}
}
}