|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 4 | + |
| 5 | +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } |
| 6 | + |
| 7 | +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } |
| 8 | + |
| 9 | +var codes = {}; |
| 10 | + |
| 11 | +function createErrorType(code, message, Base) { |
| 12 | + if (!Base) { |
| 13 | + Base = Error; |
| 14 | + } |
| 15 | + |
| 16 | + function getMessage(arg1, arg2) { |
| 17 | + if (typeof message === 'string') { |
| 18 | + return message; |
| 19 | + } else { |
| 20 | + return message(arg1, arg2); |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + var NodeError = function (_Base) { |
| 25 | + _inherits(NodeError, _Base); |
| 26 | + |
| 27 | + function NodeError(arg1, arg2) { |
| 28 | + _classCallCheck(this, NodeError); |
| 29 | + |
| 30 | + return _possibleConstructorReturn(this, (NodeError.__proto__ || Object.getPrototypeOf(NodeError)).call(this, getMessage(arg1, arg2))); |
| 31 | + } |
| 32 | + |
| 33 | + return NodeError; |
| 34 | + }(Base); |
| 35 | + |
| 36 | + NodeError.prototype.name = Base.name; |
| 37 | + NodeError.prototype.code = code; |
| 38 | + |
| 39 | + codes[code] = NodeError; |
| 40 | +} |
| 41 | + |
| 42 | +createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) { |
| 43 | + return 'The value "' + value + '" is invalid for option "' + name + '"'; |
| 44 | +}, TypeError); |
| 45 | +createErrorType('ERR_INVALID_ARG_TYPE', 'argument must be of the right type', TypeError); |
| 46 | +createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF'); |
| 47 | +createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) { |
| 48 | + return 'The ' + name + ' method is not implemented'; |
| 49 | +}); |
| 50 | +createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'premature close'); |
| 51 | +createErrorType('ERR_STREAM_DESTROYED', 'the stream was destroyed'); |
| 52 | +createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times'); |
| 53 | +createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable'); |
| 54 | +createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end'); |
| 55 | +createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError); |
| 56 | +createErrorType('ERR_UNKNOWN_ENCODING', function (arg) { |
| 57 | + return 'Unknown encoding: ' + arg; |
| 58 | +}, TypeError); |
| 59 | +createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event'); |
| 60 | + |
| 61 | +module.exports.codes = codes; |
0 commit comments