diff --git a/packages/livedata/livedata_common.js b/packages/livedata/livedata_common.js index c9af4b81dc..a919cd8cae 100644 --- a/packages/livedata/livedata_common.js +++ b/packages/livedata/livedata_common.js @@ -122,6 +122,16 @@ Meteor._CurrentInvocation = new Meteor.EnvironmentVariable; Meteor.Error = function (error, reason, details) { var self = this; + // Meteor.Error is defined on both client and server, but it only + // has a stack trace on the server. Luckily, Error.captureStackTrace + // achieves this on V8. Googling and experimentation found no way to + // capture stack traces on all browsers, so it seems that this is + // not a viable general pattern for creating custom Error + // classes. If we need to do that, we'd probably be best off setting + // a 'type' property on the Error object instead. + if (Error.captureStackTrace) + Error.captureStackTrace(self, Meteor.Error); + // Currently, a numeric code, likely similar to a HTTP code (eg, // 404, 500). That is likely to change though. self.error = error; @@ -138,6 +148,21 @@ Meteor.Error = function (error, reason, details) { // never expect this to be shown to end users, only developers, so // it doesn't need to be pretty.) self.details = details; + + // This is what gets displayed at the top of a stack trace. Current + // format is "[404]" (if no reason is set) or "File not found [404]" + if (self.reason) + self.message = self.reason + ' [' + self.error + ']'; + else + self.message = '[' + self.error + ']'; }; -Meteor.Error.prototype = new Error; +// http://davidshariff.com/blog/javascript-inheritance-patterns/ +var inherits = function (child, parent) { + var tmp = function () {}; + tmp.prototype = parent.prototype; + child.prototype = new tmp; + child.prototype.constructor = child; +}; + +inherits(Meteor.Error, Error); \ No newline at end of file