<commit_before>(function() {

  if (typeof exports !== 'undefined') {
    var _ = require('underscore');
    var util = require('./util')
  } else {
     var util = Substance.util;
  }

  var root = this;
  var errors = {};

  errors.define = function(className, code) {
    var errorClass = util.inherits(Error, {
      constructor: function(message) {
        Error.apply(this, arguments);
        this.message = message;
      },
      code: code,
      name: className,
      toJSON: function() {
        return {
          name: this.name,
          message: this.message,
          code: this.code
        };
      }
    }, {});

    if (typeof exports !== 'undefined') {
        module.exports[className] = errorClass;
    } else {
      errors[className] = errorClass;
    }

    return errorClass;
  }

  if (typeof exports === 'undefined') {
    if (!root.Substance) root.Substance = {};
    root.Substance.errors = errors;
  } else {
    module.exports = errors;
  }

}).call(this);<commit_msg>Simplified error implementation.<commit_after>(function(root) {

if (typeof exports !== 'undefined') {
  var _ = require('underscore');
  var util = require('./util')
} else {
   var util = Substance.util;
}

var errors = {};

SubstanceError = function(name, code, message) {
  this.message = message;
  this.name = name;
  this.code = code;

  this.stack = util.callstack(1);
};

SubstanceError.prototype = {
  toString: function() {
    return this.name+":"+this.message;
  },
  toJSON: function() {
    return {
      name: this.name,
      message: this.message,
      code: this.code,
      stack: this.stack
    };
  },
  printStackTrace: function() {
    for (var idx = 0; idx < this.stack.length; idx++) {
      var s = this.stack[idx];
      console.log(s.file+":"+s.line+":"+s.col, "("+s.func+")");
    }
  }
}

errors.define = function(className, code) {
  errors[className] = SubstanceError.bind(null, className, code);
  errors[className].prototype = SubstanceError.prototype;
}

if (typeof exports === 'undefined') {
  if (!root.Substance) root.Substance = {};
  root.Substance.errors = errors;
} else {
  module.exports = errors;
}

})(this);
{'fraction_non_alphanumeric': 0.1614246068455134, 'fraction_numerical': 0.0009250693802035153, 'mean_word_length': 2.7293103448275864, 'pattern_counts': {'":': 3, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7091436', 'n_tokens_mistral': 695, 'n_tokens_neox': 682, 'n_words': 149}