Skip to content
Browse files

Compiling

  • Loading branch information...
1 parent 4763012 commit d6ebecd3cafb94c8ae93673249c4d8efdcf8c29b @TrevorBurnham committed
Showing with 36 additions and 60 deletions.
  1. +36 −60 lib/err.js
View
96 lib/err.js
@@ -1,5 +1,5 @@
(function() {
- var ErrorExtras, NamedError, errInstanceMixin, instances, newErrInstance, out, _;
+ var NamedError, classes, err, _;
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
function ctor() { this.constructor = child; }
@@ -8,7 +8,6 @@
child.__super__ = parent.prototype;
return child;
};
- out = (require('styout')).instance('err');
_ = require('underscore');
NamedError = (function() {
__extends(NamedError, Error);
@@ -18,68 +17,45 @@
}
return NamedError;
})();
- ErrorExtras = {
- isLogged: false,
- log: function(message) {
- if (message == null) {
- message = this.message;
- }
- out.error(message);
- return this.isLogged = true;
+ classes = {};
+ module.exports = err = function(name, message, log) {
+ var e, sup, _ref;
+ if (log == null) {
+ log = false;
}
- };
- newErrInstance = function() {
- var instance;
- return instance = function(name, message, log) {
- var e, sup, _ref, _ref2;
- if (log == null) {
- log = instance.logByDefault;
- }
- if (arguments.length === 1) {
- _ref = [null, name, log], name = _ref[0], message = _ref[1], log = _ref[2];
- }
- if (arguments.length === 2 && typeof message === 'boolean') {
- _ref2 = [null, name, message], name = _ref2[0], message = _ref2[1], log = _ref2[2];
- }
- if (name) {
- sup = new Error(message);
- sup.name = name;
- e = new (instance.getClass(name))(name, message);
- e.stack = sup.stack;
- } else {
- e = new Error(message);
- }
- _.extend(e, ErrorExtras);
- if (log) {
- e.log();
- }
- return e;
- };
- };
- errInstanceMixin = {
- logByDefault: false,
- classes: {},
- getClass: function(name) {
- var NamedErrorSubclass;
- if (this.classes[name]) {
- return this.classes[name];
- }
- return this.classes[name] = NamedErrorSubclass = (function() {
- function NamedErrorSubclass() {
- NamedErrorSubclass.__super__.constructor.apply(this, arguments);
+ if (!_.isString(arguments[1])) {
+ _ref = ['Error', name, message], name = _ref[0], message = _ref[1], log = _ref[2];
+ }
+ sup = new Error(message);
+ sup.name = name;
+ e = new (err.getClass(name))(name, message);
+ e.stack = sup.stack;
+ _.extend(e, {
+ isLogged: false,
+ log: function(message) {
+ if (message == null) {
+ message = this.message;
}
- __extends(NamedErrorSubclass, NamedError);
- return NamedErrorSubclass;
- })();
+ console.error(message);
+ return this.isLogged = true;
+ }
+ });
+ if (log) {
+ e.log();
}
+ return e;
};
- instances = {};
- exports.instance = function(id) {
- if (instances[id]) {
- return instances[id];
+ err.getClass = function(name) {
+ var NamedErrorSubclass;
+ if (classes[name]) {
+ return classes[name];
}
- return instances[id] = _.extend(newErrInstance(), errInstanceMixin, {
- id: id
- });
+ return classes[name] = NamedErrorSubclass = (function() {
+ function NamedErrorSubclass() {
+ NamedErrorSubclass.__super__.constructor.apply(this, arguments);
+ }
+ __extends(NamedErrorSubclass, NamedError);
+ return NamedErrorSubclass;
+ })();
};
}).call(this);

0 comments on commit d6ebecd

Please sign in to comment.
Something went wrong with that request. Please try again.