UNPKG

648 BJavaScriptView Raw
1'use strict'
2
3var util = require('util')
4var cli = require('./errors')
5
6function ErrorExit (code, message) {
7 Error.call(this)
8 Error.captureStackTrace(this, this.constructor)
9 this.name = this.constructor.name
10
11 this.code = code
12 this.message = message
13}
14
15util.inherits(ErrorExit, Error)
16
17var mocking
18
19function exit (code, message) {
20 if (message) {
21 cli.error(message)
22 }
23 if (mocking) {
24 throw new ErrorExit(code, message)
25 } else {
26 process.exit(code)
27 }
28}
29
30exit.mock = function (mock) {
31 if (mock === false) {
32 mocking = false
33 } else {
34 mocking = true
35 }
36}
37
38exit.ErrorExit = ErrorExit
39
40module.exports = {
41 exit
42}