forked from jamesshore/lets_code_javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfail_fast.js
More file actions
31 lines (24 loc) · 1.27 KB
/
fail_fast.js
File metadata and controls
31 lines (24 loc) · 1.27 KB
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
// Copyright (c) 2013 Titanium I.T. LLC. All rights reserved. See LICENSE.TXT for details.
(function() {
"use strict";
exports.unlessDefined = function(variable, variableName) {
variableName = variableName ? " [" + variableName + "] " : " ";
if (variable === undefined) throw new FailFastException(exports.unlessDefined, "Required variable" + variableName + "was not defined");
};
exports.unlessTrue = function(variable, message) {
if (message === undefined) message = "Expected condition to be true";
if (variable === false) throw new FailFastException(exports.unlessTrue, message);
if (variable !== true) throw new FailFastException(exports.unlessTrue, "Expected condition to be true or false");
};
exports.unreachable = function(message) {
if (!message) message = "Unreachable code executed";
throw new FailFastException(exports.unreachable, message);
};
var FailFastException = exports.FailFastException = function(fnToRemoveFromStackTrace, message) {
if (Error.captureStackTrace) Error.captureStackTrace(this, fnToRemoveFromStackTrace); // only works on Chrome/V8
this.message = message;
};
FailFastException.prototype = new Error();
FailFastException.prototype.constructor = FailFastException;
FailFastException.prototype.name = "FailFastException";
}());