Skip to content

Fix for errors without line numbers #3

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

Merged
merged 1 commit into from
Feb 16, 2012
Merged
Show file tree
Hide file tree
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
40 changes: 19 additions & 21 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
// Save a reference to the global object (`window` in the browser, `global`
// on the server).
var root = this;

var Raven;
Raven = root.Raven = {};

var self = Raven;

Raven.VERSION = '@VERSION';

// jQuery, Zepto, or Ender owns the `$` variable.
var $ = root.jQuery || root.Zepto || root.ender;

Expand All @@ -45,22 +45,22 @@
$.each(config, function(i, option) {
self.options[i] = option;
});

};

Raven.getHeaders = function() {
var headers = {};

if (self.options.fetchHeaders) {
headers = $.ajax({type: 'HEAD', url: root.location, async: false})
.getAllResponseHeaders();
}

headers["Referer"] = document.referrer;
headers["User-Agent"] = navigator.userAgent;
return headers;
};

Raven.parseHeaders = function(headers_string) {
/*
* Parse the header string returned from getAllResponseHeaders
Expand All @@ -73,7 +73,7 @@
});
return headers;
};

Raven.getSignature = function(message, timestamp, callback) {
if (self.options.signatureUrl) {
$.post(self.options.signatureUrl, {
Expand All @@ -87,7 +87,7 @@
callback(signature);
}
};

Raven.getAuthHeader = function(signature, timestamp) {
var header = "Sentry sentry_version=2.0, ";
header += "sentry_timestamp=" + timestamp + ", ";
Expand Down Expand Up @@ -134,30 +134,28 @@
} else if (e.fileName) { // Mozilla
fileurl = e.fileName;
}

self.process(e, fileurl, lineno, e.stack);
};

Raven.process = function(message, fileurl, lineno, stack, timestamp) {
var label, traceback, stacktrace, data, encoded_msg, type,
url = root.location.origin + root.location.pathname,
querystring = root.location.search.slice(1); // Remove the ?

if (typeof(message) === 'object') {
type = message.name;
message = message.message;
}

if (lineno) {
label = message + " at " + lineno;
}


label = lineno ? message + " at " + lineno : message;

if (stack) {
try {
traceback = self.parseTraceback(stack);
} catch (err) {}
}

if (traceback) {
stacktrace = {"frames": traceback};
fileurl = fileurl || traceback[0].filename;
Expand All @@ -169,7 +167,7 @@
}]
};
}

data = {
"message": label,
"culprit": fileurl,
Expand All @@ -182,15 +180,15 @@
"logger": self.options.logger,
"site": self.options.site
};

if (!self.options.testMode) {
data["sentry.interfaces.Http"] = {
"url": url,
"querystring": querystring,
"headers": self.getHeaders()
};
}

timestamp = timestamp || (new Date).getTime();
encoded_msg = $P.base64_encode(JSON.stringify(data));
self.getSignature(encoded_msg, timestamp, function(signature) {
Expand Down
19 changes: 14 additions & 5 deletions test/exception.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
$(document).ready(function() {

module("Raven.captureException");

test("should collect error information and report to Sentry", function() {
try {
varThatDoesNotExist++;
} catch(err) {
Raven.captureException(err);
}
data = JSON.parse($P.base64_decode(ajax_calls[0].data));

var data = JSON.parse($P.base64_decode(ajax_calls[0].data));

equal(data.culprit.slice(-12), 'exception.js',
'the culprit should be the exception.js unit test file');
equal(data.logger, 'javascript',
Expand All @@ -20,5 +20,14 @@ $(document).ready(function() {
equal(data['sentry.interfaces.Exception'].type, 'ReferenceError',
'the error should be a ReferenceError');
});


test("should have error message without line number", function() {
Raven.captureException(new Error('ManuallyThrownError'));

var data = JSON.parse($P.base64_decode(ajax_calls[0].data));

equal(data.message, 'ManuallyThrownError',
'the message should match');
});

});