UNPKG

940 BJavaScriptView Raw
1'use strict';
2var debug = require('debug');
3
4function SilentError(message) {
5 if (!(this instanceof SilentError)) {
6 throw new TypeError('SilentError must be instantiated with `new`');
7 }
8
9 this.name = 'SilentError';
10 this.message = message;
11 this.isSilentError = true;
12
13 if (process.env.SILENT_ERROR === 'verbose' || process.env.EMBER_VERBOSE_ERRORS === 'true') {
14 this.stack = (new Error()).stack;
15 this.suppressedStacktrace = false;
16 } else {
17 this.suppressedStacktrace = true;
18 }
19}
20
21SilentError.prototype = Object.create(Error.prototype);
22SilentError.prototype.constructor = SilentError;
23
24SilentError.debugOrThrow = function debugOrThrow(label, e) {
25 // if the error is a SilentError, ignore
26 if(e && e.isSilentError) {
27 // ignore this error, invalid blueprints are handled in run
28 debug(label)(e);
29 } else {
30 // rethrow all other errors
31 throw e;
32 }
33};
34
35module.exports = SilentError;