UNPKG

delvejs

Version:

Node client for a Delve server for debugging Go code

141 lines (99 loc) 4.56 kB
/** Delve Client Errors @description Custom errors for the Delve client, many of which wrap special errors that can be given by Delve itself @author tylerFowler **/ 'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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; } 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; } var error = module.exports = {}; var DelveErr = 'DelveError'; /** @class BaseError @desc Provides the base for all custom errors, meant to be extended **/ var BaseError = function (_Error) { _inherits(BaseError, _Error); function BaseError(msg) { _classCallCheck(this, BaseError); var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(BaseError).call(this, msg)); if (Error.captureStackTrace) Error.captureStackTrace(_this, _this.constructor); _this.name = DelveErr + 'BaseError'; return _this; } return BaseError; }(Error); error.BaseError = BaseError; /** @class DelveServerError @desc Thrown when the Delve RPC API gives back an error, acts as a wrapper for issues that arise within Delve rather than the library **/ var DelveServerError = function (_BaseError) { _inherits(DelveServerError, _BaseError); function DelveServerError(err) { _classCallCheck(this, DelveServerError); var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(DelveServerError).call(this, 'Delve reported error: ' + err)); _this2.error = err; _this2.name = DelveErr + 'ServerError'; return _this2; } return DelveServerError; }(BaseError); error.DelveServerError = DelveServerError; /** @class MalformedLocationError @desc Thrown when a given location is reported as invalid from Delve @param { String } locationArg @param { Error } err is the original error from the RPC client **/ var MalformedLocationError = function (_BaseError2) { _inherits(MalformedLocationError, _BaseError2); function MalformedLocationError(locationArg, err) { _classCallCheck(this, MalformedLocationError); var _this3 = _possibleConstructorReturn(this, Object.getPrototypeOf(MalformedLocationError).call(this, 'Location invalid: ' + err.toString())); _this3.error = err; _this3.name = DelveErr + 'MalformedLocationError'; return _this3; } return MalformedLocationError; }(BaseError); error.MalformedLocationError = MalformedLocationError; /** @class MalformedBreakpointError @desc Thrown when a breakpoint from the Delve server cannot be parsed **/ var MalformedBreakpointError = function (_BaseError3) { _inherits(MalformedBreakpointError, _BaseError3); function MalformedBreakpointError(ogErr) { _classCallCheck(this, MalformedBreakpointError); var msg = 'Error creating breakpoint: ' + ogErr; var _this4 = _possibleConstructorReturn(this, Object.getPrototypeOf(MalformedBreakpointError).call(this, msg)); _this4.parseError = ogErr; _this4.name = DelveErr + 'MalformedBreakpointError'; return _this4; } return MalformedBreakpointError; }(BaseError); error.MalformedBreakpointError = MalformedBreakpointError; /** @class DebuggerExited @desc Thrown when the debugger has reported an exited state, usually after a continue command @param { DebuggerState } state **/ var DebuggerExited = function (_BaseError4) { _inherits(DebuggerExited, _BaseError4); function DebuggerExited(state) { _classCallCheck(this, DebuggerExited); var _this5 = _possibleConstructorReturn(this, Object.getPrototypeOf(DebuggerExited).call(this, 'Process has exited with status ' + state.exitStatus)); _this5.exitStatus = state.exitStatus; _this5.lastKnownState = state; _this5.name = DelveErr + 'DebuggerExited'; return _this5; } return DebuggerExited; }(BaseError); error.DebuggerExited = DebuggerExited;