Template.simple.events({
"click button": function() {
fetchFromServer("getSomeTweets", displayTweets);
}
});
function displayTweets(err, date) {
console.log(data.tweets);
}
Template.without_async.events({
"click button": function() {
throw new Error("oops. something went wrong");
}
});
Template.with_async.events({
"click button": function() {
setTimeout(function() {
throw new Error("oops. something went wrong");
}, 100);
}
});
On Users Browser
We can't Debug It
User is your Grandma
(Code is not minified yet)
function ReportError(type, data) {
console.log("A new Error of type: " + type);
console.log(data);
}
Template.window_onerror.events({
"click button": function() {
fetchFromServer("getSomeTweets", displayTweets);
}
});
function displayTweets(err, date) {
console.log(data.tweets);
}
window.onerror = function() {
ReportError("window.onerror", arguments);
};
Template.trycatch1.events({
"click button": function() {
try {
throw new Error("oops. something went wrong");
} catch(ex) {
ReportError("trycatch1", ex);
}
}
});
Template.trycatch2.events({
"click button": function() {
try {
setTimeout(function() {
throw new Error("oops. something went wrong");
}, 100);
} catch(ex) {
ReportError("trycatch2", ex);
}
}
});
window.onerror is limited
tracking errors manually is hard
no async stacks
var reporter = {
onError: function(ex) {
console.log(ex);
}
};
zone.fork(reporter).run(function() {
throw new Error('oops something goes wrong');
});
var reporter = {
onError: function(ex) {
console.log(ex);
}
};
zone.fork(reporter).run(function() {
setTimeout(function() {
throw new Error('oops something goes wrong inside setTimeout');
}, 1000);
});
zone.fork(Zone.longStackTraceZone);
Template.with_async.events({
"click button": function() {
setTimeout(function() {
throw new Error("oops. something went wrong");
}, 100);
}
});
zone.fork(Zone.longStackTraceZone);
Template.with_async.events({
"click button": function() {
setTimeout(function() {
throw new Error("oops. something went wrong");
}, 100);
}
});
We need context
Set of Actions Occured
Error Message
var originalMeteorCall = Meteor.call;
Meteor.call = function(methodName) {
var args = Array.prototype.slice.call(arguments, 1);
zone.addAction("Meteor.call", {
method: methodName,
args: args
}};
originalMeteorCall.apply(this, arguments);
}
try {
this.beforeTask();
result = fn.apply(applyTo, applyWith);
} catch (e) {
if (zone.onError) {
zone.onError(e);
} else {
throw e;
}
} finally {
this.afterTask();
window.zone = oldZone;
}