exception.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // YAML error class. http://stackoverflow.com/questions/8458984
  2. //
  3. 'use strict';
  4. function YAMLException(reason, mark) {
  5. // Super constructor
  6. Error.call(this);
  7. // Include stack trace in error object
  8. if (Error.captureStackTrace) {
  9. // Chrome and NodeJS
  10. Error.captureStackTrace(this, this.constructor);
  11. } else {
  12. // FF, IE 10+ and Safari 6+. Fallback for others
  13. this.stack = (new Error()).stack || '';
  14. }
  15. this.name = 'YAMLException';
  16. this.reason = reason;
  17. this.mark = mark;
  18. this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : '');
  19. }
  20. // Inherit from Error
  21. YAMLException.prototype = Object.create(Error.prototype);
  22. YAMLException.prototype.constructor = YAMLException;
  23. YAMLException.prototype.toString = function toString(compact) {
  24. var result = this.name + ': ';
  25. result += this.reason || '(unknown reason)';
  26. if (!compact && this.mark) {
  27. result += ' ' + this.mark.toString();
  28. }
  29. return result;
  30. };
  31. module.exports = YAMLException;