Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to send custom stack traces to _ratchet.push #1

Merged
merged 4 commits into from
Dec 13, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions src/ratchet.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,20 @@
push: function(args, callback) {
if (args instanceof Error) {
this.handleError(args, callback);
} else if (args instanceof Object &&
} else if (typeof args == 'object' &&
!args.hasOwnProperty('msg') &&
args.hasOwnProperty(0) && args.hasOwnProperty(1) && args.hasOwnProperty(2)) {
// 'args instanceof Array' for above check doesn't work.
this.handleUncaughtError(args[0], args[1], args[2]);
} else if (args instanceof Object &&
} else if (typeof args == 'object' &&
args.hasOwnProperty("_t") &&
args['_t'] === 'uncaught') {
this.handleUncaughtError(args.e, args.u, args.l);
} else if (args instanceof Object) {
} else if (typeof args == 'object' &&
args.hasOwnProperty("_t") &&
args['_t'] === 'trace') {
this.handleErrorTrace(args, callback);
} else if (typeof args == 'object') {
this.handleMessage(args, callback);
} else {
this.handleMessage({level: 'info', msg: args.toString()}, callback);
Expand Down Expand Up @@ -456,18 +460,14 @@
errClass = errClassMatch[errClassMatch.length - 1];
errMsg = errMsg.replace((errClassMatch[errClassMatch.length - 2] || '') + errClass + ':', '');
}
this.items.push({
body: {
trace: {

this._pushTrace({
exception: {
'class': errClass,
message: errMsg
},
frames: frames
}
}
});
this.handleEvents();
}, null);
},

handleError: function(err, callback) {
Expand All @@ -488,6 +488,35 @@
}
}

this._pushTrace(trace, callback);
},

/*
* Reports raw trace objects. This is used for building enhanced or modified stack traces.
*
* var trace = {
* exception: {'class': 'TypeError', 'message': 'blah'},
* trace: [...list of frames...]
* }
* _ratchet.push({_t: 'trace', trace: trace})
*
*/
handleErrorTrace: function(obj, callback) {
if (!obj.trace) {
var errorMsg = "Trace objects must contain the property 'trace'";
this.logger(errorMsg);
if (callback) {
callback(new Error(errorMsg));
}
return;
}

this._pushTrace(obj.trace, callback);
},

// Internal function for pushing stack traces
_pushTrace: function(trace, callback) {

var item = {body: {trace: trace}};
if (callback) {
item.callback = callback;
Expand All @@ -496,7 +525,7 @@
this.items.push(item);
this.handleEvents();
},

handleEvents: function() {
if (this.handler) {
clearTimeout(this.handler);
Expand Down