Skip to content

Commit

Permalink
(error) retrieve callsites data from error
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud committed Feb 7, 2017
1 parent 3f331ee commit ea7678a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
20 changes: 14 additions & 6 deletions lib/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var util = require('util');
var Common = require('./common.js');

var Options = require('./configuration.js');

var callsites = require('error-callsites')
var Transport = require('./utils/transport.js');

var Notify = {};
Expand All @@ -31,7 +31,7 @@ Notify.catchAll = function(opts) {
error : opts.errors
});

if (process.env.exec_mode == 'cluster_mode')
if (process.env.exec_mode === 'cluster_mode')
return false;

function getUncaughtExceptionListener(listener) {
Expand All @@ -42,16 +42,15 @@ Notify.catchAll = function(opts) {
err._length = err.length;
delete err.length;
}

if (listener === 'unhandledRejection') {
error = 'You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:\n' + error;
}

console.error(error);

if (err)
var errObj = jsonize(err);

var errObj = Notify._interpretError(err);
Transport.send({
type : 'process:exception',
data : errObj !== undefined ? errObj : {message: 'No error but ' + listener + ' was caught!' }
Expand Down Expand Up @@ -93,6 +92,15 @@ Notify._interpretError = function(err) {
}
else if (err instanceof Error) {
// Error object type processing
err.stack;
if (err.__error_callsites) {
var stackFrames = [];
err.__error_callsites.forEach(function(callSite) {
stackFrames.push({ file_name: callSite.getFileName(), line_number: callSite.getLineNumber()});
});
err.stackframes = stackFrames;
delete err.__error_callsites;
}
s_err = err;
}

Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "pmx",
"version": "1.0.0",
"version": "1.0.1",
"description": "PM2/Keymetrics advanced API",
"main": "index.js",
"dependencies": {
"debug": "^2.6",
"error-callsites": "^1.0.1",
"json-stringify-safe": "^5.0",
"vxx": "^1.0.0"
},
Expand All @@ -14,10 +15,10 @@
"should": "*",
"mocha": "*",
"shelljs": "*",
"pm2" : "Unitech/pm2#lazer",
"pm2-axon" : "*",
"nssocket" : "*",
"mongoose" : "*"
"pm2": "Unitech/pm2#lazer",
"pm2-axon": "*",
"nssocket": "*",
"mongoose": "*"
},
"scripts": {
"test": "DEBUG='axm:*' mocha test/*.mocha.js"
Expand Down

0 comments on commit ea7678a

Please sign in to comment.