{"ast":null,"code":"/**\n * exception-handler.js: Object for handling uncaughtException events.\n *\n * (C) 2010 Charlie Robbins\n * MIT LICENCE\n */\n'use strict';\n\nfunction _classCallCheck(instance, Constructor) {\n  if (!(instance instanceof Constructor)) {\n    throw new TypeError(\"Cannot call a class as a function\");\n  }\n}\n\nfunction _defineProperties(target, props) {\n  for (var i = 0; i < props.length; i++) {\n    var descriptor = props[i];\n    descriptor.enumerable = descriptor.enumerable || false;\n    descriptor.configurable = true;\n    if (\"value\" in descriptor) descriptor.writable = true;\n    Object.defineProperty(target, descriptor.key, descriptor);\n  }\n}\n\nfunction _createClass(Constructor, protoProps, staticProps) {\n  if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n  if (staticProps) _defineProperties(Constructor, staticProps);\n  return Constructor;\n}\n\nvar os = require('os');\n\nvar asyncForEach = require('async/forEach');\n\nvar debug = require('@dabh/diagnostics')('winston:exception');\n\nvar once = require('one-time');\n\nvar stackTrace = require('stack-trace');\n\nvar ExceptionStream = require('./exception-stream');\n/**\n * Object for handling uncaughtException events.\n * @type {ExceptionHandler}\n */\n\n\nmodule.exports = /*#__PURE__*/function () {\n  /**\n   * TODO: add contructor description\n   * @param {!Logger} logger - TODO: add param description\n   */\n  function ExceptionHandler(logger) {\n    _classCallCheck(this, ExceptionHandler);\n\n    if (!logger) {\n      throw new Error('Logger is required to handle exceptions');\n    }\n\n    this.logger = logger;\n    this.handlers = new Map();\n  }\n  /**\n   * Handles `uncaughtException` events for the current process by adding any\n   * handlers passed in.\n   * @returns {undefined}\n   */\n\n\n  _createClass(ExceptionHandler, [{\n    key: \"handle\",\n    value: function handle() {\n      var _this = this;\n\n      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n        args[_key] = arguments[_key];\n      }\n\n      args.forEach(function (arg) {\n        if (Array.isArray(arg)) {\n          return arg.forEach(function (handler) {\n            return _this._addHandler(handler);\n          });\n        }\n\n        _this._addHandler(arg);\n      });\n\n      if (!this.catcher) {\n        this.catcher = this._uncaughtException.bind(this);\n        process.on('uncaughtException', this.catcher);\n      }\n    }\n    /**\n     * Removes any handlers to `uncaughtException` events for the current\n     * process. This does not modify the state of the `this.handlers` set.\n     * @returns {undefined}\n     */\n\n  }, {\n    key: \"unhandle\",\n    value: function unhandle() {\n      var _this2 = this;\n\n      if (this.catcher) {\n        process.removeListener('uncaughtException', this.catcher);\n        this.catcher = false;\n        Array.from(this.handlers.values()).forEach(function (wrapper) {\n          return _this2.logger.unpipe(wrapper);\n        });\n      }\n    }\n    /**\n     * TODO: add method description\n     * @param {Error} err - Error to get information about.\n     * @returns {mixed} - TODO: add return description.\n     */\n\n  }, {\n    key: \"getAllInfo\",\n    value: function getAllInfo(err) {\n      var message = err.message;\n\n      if (!message && typeof err === 'string') {\n        message = err;\n      }\n\n      return {\n        error: err,\n        // TODO (indexzero): how do we configure this?\n        level: 'error',\n        message: [\"uncaughtException: \".concat(message || '(no error message)'), err.stack || '  No stack trace'].join('\\n'),\n        stack: err.stack,\n        exception: true,\n        date: new Date().toString(),\n        process: this.getProcessInfo(),\n        os: this.getOsInfo(),\n        trace: this.getTrace(err)\n      };\n    }\n    /**\n     * Gets all relevant process information for the currently running process.\n     * @returns {mixed} - TODO: add return description.\n     */\n\n  }, {\n    key: \"getProcessInfo\",\n    value: function getProcessInfo() {\n      return {\n        pid: process.pid,\n        uid: process.getuid ? process.getuid() : null,\n        gid: process.getgid ? process.getgid() : null,\n        cwd: process.cwd(),\n        execPath: process.execPath,\n        version: process.version,\n        argv: process.argv,\n        memoryUsage: process.memoryUsage()\n      };\n    }\n    /**\n     * Gets all relevant OS information for the currently running process.\n     * @returns {mixed} - TODO: add return description.\n     */\n\n  }, {\n    key: \"getOsInfo\",\n    value: function getOsInfo() {\n      return {\n        loadavg: os.loadavg(),\n        uptime: os.uptime()\n      };\n    }\n    /**\n     * Gets a stack trace for the specified error.\n     * @param {mixed} err - TODO: add param description.\n     * @returns {mixed} - TODO: add return description.\n     */\n\n  }, {\n    key: \"getTrace\",\n    value: function getTrace(err) {\n      var trace = err ? stackTrace.parse(err) : stackTrace.get();\n      return trace.map(function (site) {\n        return {\n          column: site.getColumnNumber(),\n          file: site.getFileName(),\n          \"function\": site.getFunctionName(),\n          line: site.getLineNumber(),\n          method: site.getMethodName(),\n          \"native\": site.isNative()\n        };\n      });\n    }\n    /**\n     * Helper method to add a transport as an exception handler.\n     * @param {Transport} handler - The transport to add as an exception handler.\n     * @returns {void}\n     */\n\n  }, {\n    key: \"_addHandler\",\n    value: function _addHandler(handler) {\n      if (!this.handlers.has(handler)) {\n        handler.handleExceptions = true;\n        var wrapper = new ExceptionStream(handler);\n        this.handlers.set(handler, wrapper);\n        this.logger.pipe(wrapper);\n      }\n    }\n    /**\n     * Logs all relevant information around the `err` and exits the current\n     * process.\n     * @param {Error} err - Error to handle\n     * @returns {mixed} - TODO: add return description.\n     * @private\n     */\n\n  }, {\n    key: \"_uncaughtException\",\n    value: function _uncaughtException(err) {\n      var info = this.getAllInfo(err);\n\n      var handlers = this._getExceptionHandlers(); // Calculate if we should exit on this error\n\n\n      var doExit = typeof this.logger.exitOnError === 'function' ? this.logger.exitOnError(err) : this.logger.exitOnError;\n      var timeout;\n\n      if (!handlers.length && doExit) {\n        // eslint-disable-next-line no-console\n        console.warn('winston: exitOnError cannot be true with no exception handlers.'); // eslint-disable-next-line no-console\n\n        console.warn('winston: not exiting process.');\n        doExit = false;\n      }\n\n      function gracefulExit() {\n        debug('doExit', doExit);\n        debug('process._exiting', process._exiting);\n\n        if (doExit && !process._exiting) {\n          // Remark: Currently ignoring any exceptions from transports when\n          // catching uncaught exceptions.\n          if (timeout) {\n            clearTimeout(timeout);\n          } // eslint-disable-next-line no-process-exit\n\n\n          process.exit(1);\n        }\n      }\n\n      if (!handlers || handlers.length === 0) {\n        return process.nextTick(gracefulExit);\n      } // Log to all transports attempting to listen for when they are completed.\n\n\n      asyncForEach(handlers, function (handler, next) {\n        var done = once(next);\n        var transport = handler.transport || handler; // Debug wrapping so that we can inspect what's going on under the covers.\n\n        function onDone(event) {\n          return function () {\n            debug(event);\n            done();\n          };\n        }\n\n        transport._ending = true;\n        transport.once('finish', onDone('finished'));\n        transport.once('error', onDone('error'));\n      }, function () {\n        return doExit && gracefulExit();\n      });\n      this.logger.log(info); // If exitOnError is true, then only allow the logging of exceptions to\n      // take up to `3000ms`.\n\n      if (doExit) {\n        timeout = setTimeout(gracefulExit, 3000);\n      }\n    }\n    /**\n     * Returns the list of transports and exceptionHandlers for this instance.\n     * @returns {Array} - List of transports and exceptionHandlers for this\n     * instance.\n     * @private\n     */\n\n  }, {\n    key: \"_getExceptionHandlers\",\n    value: function _getExceptionHandlers() {\n      // Remark (indexzero): since `logger.transports` returns all of the pipes\n      // from the _readableState of the stream we actually get the join of the\n      // explicit handlers and the implicit transports with\n      // `handleExceptions: true`\n      return this.logger.transports.filter(function (wrap) {\n        var transport = wrap.transport || wrap;\n        return transport.handleExceptions;\n      });\n    }\n  }]);\n\n  return ExceptionHandler;\n}();","map":{"version":3,"sources":["D:/Development/Work/CENOS/cenos-ui/node_modules/winston/dist/winston/exception-handler.js"],"names":["_classCallCheck","instance","Constructor","TypeError","_defineProperties","target","props","i","length","descriptor","enumerable","configurable","writable","Object","defineProperty","key","_createClass","protoProps","staticProps","prototype","os","require","asyncForEach","debug","once","stackTrace","ExceptionStream","module","exports","ExceptionHandler","logger","Error","handlers","Map","value","handle","_this","_len","arguments","args","Array","_key","forEach","arg","isArray","handler","_addHandler","catcher","_uncaughtException","bind","process","on","unhandle","_this2","removeListener","from","values","wrapper","unpipe","getAllInfo","err","message","error","level","concat","stack","join","exception","date","Date","toString","getProcessInfo","getOsInfo","trace","getTrace","pid","uid","getuid","gid","getgid","cwd","execPath","version","argv","memoryUsage","loadavg","uptime","parse","get","map","site","column","getColumnNumber","file","getFileName","getFunctionName","line","getLineNumber","method","getMethodName","isNative","has","handleExceptions","set","pipe","info","_getExceptionHandlers","doExit","exitOnError","timeout","console","warn","gracefulExit","_exiting","clearTimeout","exit","nextTick","next","done","transport","onDone","event","_ending","log","setTimeout","transports","filter","wrap"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,eAAT,CAAyBC,QAAzB,EAAmCC,WAAnC,EAAgD;AAAE,MAAI,EAAED,QAAQ,YAAYC,WAAtB,CAAJ,EAAwC;AAAE,UAAM,IAAIC,SAAJ,CAAc,mCAAd,CAAN;AAA2D;AAAE;;AAEzJ,SAASC,iBAAT,CAA2BC,MAA3B,EAAmCC,KAAnC,EAA0C;AAAE,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,KAAK,CAACE,MAA1B,EAAkCD,CAAC,EAAnC,EAAuC;AAAE,QAAIE,UAAU,GAAGH,KAAK,CAACC,CAAD,CAAtB;AAA2BE,IAAAA,UAAU,CAACC,UAAX,GAAwBD,UAAU,CAACC,UAAX,IAAyB,KAAjD;AAAwDD,IAAAA,UAAU,CAACE,YAAX,GAA0B,IAA1B;AAAgC,QAAI,WAAWF,UAAf,EAA2BA,UAAU,CAACG,QAAX,GAAsB,IAAtB;AAA4BC,IAAAA,MAAM,CAACC,cAAP,CAAsBT,MAAtB,EAA8BI,UAAU,CAACM,GAAzC,EAA8CN,UAA9C;AAA4D;AAAE;;AAE7T,SAASO,YAAT,CAAsBd,WAAtB,EAAmCe,UAAnC,EAA+CC,WAA/C,EAA4D;AAAE,MAAID,UAAJ,EAAgBb,iBAAiB,CAACF,WAAW,CAACiB,SAAb,EAAwBF,UAAxB,CAAjB;AAAsD,MAAIC,WAAJ,EAAiBd,iBAAiB,CAACF,WAAD,EAAcgB,WAAd,CAAjB;AAA6C,SAAOhB,WAAP;AAAqB;;AAEvN,IAAIkB,EAAE,GAAGC,OAAO,CAAC,IAAD,CAAhB;;AAEA,IAAIC,YAAY,GAAGD,OAAO,CAAC,eAAD,CAA1B;;AAEA,IAAIE,KAAK,GAAGF,OAAO,CAAC,mBAAD,CAAP,CAA6B,mBAA7B,CAAZ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CAAC6F,IAAD,CAAf;AACA,YAAIE,SAAS,GAAG1E,OAAO,CAAC0E,SAAR,IAAqB1E,OAArC,CAF8C,CAEA;;AAE9C,iBAAS2E,MAAT,CAAgBC,KAAhB,EAAuB;AACrB,iBAAO,YAAY;AACjBlG,YAAAA,KAAK,CAACkG,KAAD,CAAL;AACAH,YAAAA,IAAI;AACL,WAHD;AAID;;AAEDC,QAAAA,SAAS,CAACG,OAAV,GAAoB,IAApB;AACAH,QAAAA,SAAS,CAAC/F,IAAV,CAAe,QAAf,EAAyBgG,MAAM,CAAC,UAAD,CAA/B;AACAD,QAAAA,SAAS,CAAC/F,IAAV,CAAe,OAAf,EAAwBgG,MAAM,CAAC,OAAD,CAA9B;AACD,OAdW,EAcT,YAAY;AACb,eAAOb,MAAM,IAAIK,YAAY,EAA7B;AACD,OAhBW,CAAZ;AAiBA,WAAKlF,MAAL,CAAY6F,GAAZ,CAAgBlB,IAAhB,EAvDsC,CAuDf;AACvB;;AAEA,UAAIE,MAAJ,EAAY;AACVE,QAAAA,OAAO,GAAGe,UAAU,CAACZ,YAAD,EAAe,IAAf,CAApB;AACD;AACF;AACD;AACJ;AACA;AACA;AACA;AACA;;AArEK,GApJ4B,EA2N5B;AACDjG,IAAAA,GAAG,EAAE,uBADJ;AAEDmB,IAAAA,KAAK,EAAE,SAASwE,qBAAT,GAAiC;AACtC;AACA;AACA;AACA;AACA,aAAO,KAAK5E,MAAL,CAAY+F,UAAZ,CAAuBC,MAAvB,CAA8B,UAAUC,IAAV,EAAgB;AACnD,YAAIR,SAAS,GAAGQ,IAAI,CAACR,SAAL,IAAkBQ,IAAlC;AACA,eAAOR,SAAS,CAACjB,gBAAjB;AACD,OAHM,CAAP;AAID;AAXA,GA3N4B,CAAnB,CAAZ;;AAyOA,SAAOzE,gBAAP;AACD,CAhQ6B,EAA9B","sourcesContent":["/**\n * exception-handler.js: Object for handling uncaughtException events.\n *\n * (C) 2010 Charlie Robbins\n * MIT LICENCE\n */\n'use strict';\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nvar os = require('os');\n\nvar asyncForEach = require('async/forEach');\n\nvar debug = require('@dabh/diagnostics')('winston:exception');\n\nvar once = require('one-time');\n\nvar stackTrace = require('stack-trace');\n\nvar ExceptionStream = require('./exception-stream');\n/**\n * Object for handling uncaughtException events.\n * @type {ExceptionHandler}\n */\n\n\nmodule.exports = /*#__PURE__*/function () {\n  /**\n   * TODO: add contructor description\n   * @param {!Logger} logger - TODO: add param description\n   */\n  function ExceptionHandler(logger) {\n    _classCallCheck(this, ExceptionHandler);\n\n    if (!logger) {\n      throw new Error('Logger is required to handle exceptions');\n    }\n\n    this.logger = logger;\n    this.handlers = new Map();\n  }\n  /**\n   * Handles `uncaughtException` events for the current process by adding any\n   * handlers passed in.\n   * @returns {undefined}\n   */\n\n\n  _createClass(ExceptionHandler, [{\n    key: \"handle\",\n    value: function handle() {\n      var _this = this;\n\n      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n        args[_key] = arguments[_key];\n      }\n\n      args.forEach(function (arg) {\n        if (Array.isArray(arg)) {\n          return arg.forEach(function (handler) {\n            return _this._addHandler(handler);\n          });\n        }\n\n        _this._addHandler(arg);\n      });\n\n      if (!this.catcher) {\n        this.catcher = this._uncaughtException.bind(this);\n        process.on('uncaughtException', this.catcher);\n      }\n    }\n    /**\n     * Removes any handlers to `uncaughtException` events for the current\n     * process. This does not modify the state of the `this.handlers` set.\n     * @returns {undefined}\n     */\n\n  }, {\n    key: \"unhandle\",\n    value: function unhandle() {\n      var _this2 = this;\n\n      if (this.catcher) {\n        process.removeListener('uncaughtException', this.catcher);\n        this.catcher = false;\n        Array.from(this.handlers.values()).forEach(function (wrapper) {\n          return _this2.logger.unpipe(wrapper);\n        });\n      }\n    }\n    /**\n     * TODO: add method description\n     * @param {Error} err - Error to get information about.\n     * @returns {mixed} - TODO: add return description.\n     */\n\n  }, {\n    key: \"getAllInfo\",\n    value: function getAllInfo(err) {\n      var message = err.message;\n\n      if (!message && typeof err === 'string') {\n        message = err;\n      }\n\n      return {\n        error: err,\n        // TODO (indexzero): how do we configure this?\n        level: 'error',\n        message: [\"uncaughtException: \".concat(message || '(no error message)'), err.stack || '  No stack trace'].join('\\n'),\n        stack: err.stack,\n        exception: true,\n        date: new Date().toString(),\n        process: this.getProcessInfo(),\n        os: this.getOsInfo(),\n        trace: this.getTrace(err)\n      };\n    }\n    /**\n     * Gets all relevant process information for the currently running process.\n     * @returns {mixed} - TODO: add return description.\n     */\n\n  }, {\n    key: \"getProcessInfo\",\n    value: function getProcessInfo() {\n      return {\n        pid: process.pid,\n        uid: process.getuid ? process.getuid() : null,\n        gid: process.getgid ? process.getgid() : null,\n        cwd: process.cwd(),\n        execPath: process.execPath,\n        version: process.version,\n        argv: process.argv,\n        memoryUsage: process.memoryUsage()\n      };\n    }\n    /**\n     * Gets all relevant OS information for the currently running process.\n     * @returns {mixed} - TODO: add return description.\n     */\n\n  }, {\n    key: \"getOsInfo\",\n    value: function getOsInfo() {\n      return {\n        loadavg: os.loadavg(),\n        uptime: os.uptime()\n      };\n    }\n    /**\n     * Gets a stack trace for the specified error.\n     * @param {mixed} err - TODO: add param description.\n     * @returns {mixed} - TODO: add return description.\n     */\n\n  }, {\n    key: \"getTrace\",\n    value: function getTrace(err) {\n      var trace = err ? stackTrace.parse(err) : stackTrace.get();\n      return trace.map(function (site) {\n        return {\n          column: site.getColumnNumber(),\n          file: site.getFileName(),\n          \"function\": site.getFunctionName(),\n          line: site.getLineNumber(),\n          method: site.getMethodName(),\n          \"native\": site.isNative()\n        };\n      });\n    }\n    /**\n     * Helper method to add a transport as an exception handler.\n     * @param {Transport} handler - The transport to add as an exception handler.\n     * @returns {void}\n     */\n\n  }, {\n    key: \"_addHandler\",\n    value: function _addHandler(handler) {\n      if (!this.handlers.has(handler)) {\n        handler.handleExceptions = true;\n        var wrapper = new ExceptionStream(handler);\n        this.handlers.set(handler, wrapper);\n        this.logger.pipe(wrapper);\n      }\n    }\n    /**\n     * Logs all relevant information around the `err` and exits the current\n     * process.\n     * @param {Error} err - Error to handle\n     * @returns {mixed} - TODO: add return description.\n     * @private\n     */\n\n  }, {\n    key: \"_uncaughtException\",\n    value: function _uncaughtException(err) {\n      var info = this.getAllInfo(err);\n\n      var handlers = this._getExceptionHandlers(); // Calculate if we should exit on this error\n\n\n      var doExit = typeof this.logger.exitOnError === 'function' ? this.logger.exitOnError(err) : this.logger.exitOnError;\n      var timeout;\n\n      if (!handlers.length && doExit) {\n        // eslint-disable-next-line no-console\n        console.warn('winston: exitOnError cannot be true with no exception handlers.'); // eslint-disable-next-line no-console\n\n        console.warn('winston: not exiting process.');\n        doExit = false;\n      }\n\n      function gracefulExit() {\n        debug('doExit', doExit);\n        debug('process._exiting', process._exiting);\n\n        if (doExit && !process._exiting) {\n          // Remark: Currently ignoring any exceptions from transports when\n          // catching uncaught exceptions.\n          if (timeout) {\n            clearTimeout(timeout);\n          } // eslint-disable-next-line no-process-exit\n\n\n          process.exit(1);\n        }\n      }\n\n      if (!handlers || handlers.length === 0) {\n        return process.nextTick(gracefulExit);\n      } // Log to all transports attempting to listen for when they are completed.\n\n\n      asyncForEach(handlers, function (handler, next) {\n        var done = once(next);\n        var transport = handler.transport || handler; // Debug wrapping so that we can inspect what's going on under the covers.\n\n        function onDone(event) {\n          return function () {\n            debug(event);\n            done();\n          };\n        }\n\n        transport._ending = true;\n        transport.once('finish', onDone('finished'));\n        transport.once('error', onDone('error'));\n      }, function () {\n        return doExit && gracefulExit();\n      });\n      this.logger.log(info); // If exitOnError is true, then only allow the logging of exceptions to\n      // take up to `3000ms`.\n\n      if (doExit) {\n        timeout = setTimeout(gracefulExit, 3000);\n      }\n    }\n    /**\n     * Returns the list of transports and exceptionHandlers for this instance.\n     * @returns {Array} - List of transports and exceptionHandlers for this\n     * instance.\n     * @private\n     */\n\n  }, {\n    key: \"_getExceptionHandlers\",\n    value: function _getExceptionHandlers() {\n      // Remark (indexzero): since `logger.transports` returns all of the pipes\n      // from the _readableState of the stream we actually get the join of the\n      // explicit handlers and the implicit transports with\n      // `handleExceptions: true`\n      return this.logger.transports.filter(function (wrap) {\n        var transport = wrap.transport || wrap;\n        return transport.handleExceptions;\n      });\n    }\n  }]);\n\n  return ExceptionHandler;\n}();"]},"metadata":{},"sourceType":"script"}