Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a separate 'parsers' library so parsers can be tested independe…

…ntly
  • Loading branch information...
commit 4c79681cd4599e9086d8d4245be5bf6d656e3fe7 1 parent 252dc38
Matt Robenolt mattrobenolt authored
Showing with 26 additions and 13 deletions.
  1. +5 −13 lib/client.js
  2. +21 −0 lib/parsers.js
18 lib/client.js
View
@@ -1,4 +1,5 @@
-var zlib = require('zlib'),
+var parsers = require('./parsers'),
+ zlib = require('zlib'),
utils = require('./utils'),
parseUrl = require('url').parse,
uuid = require('node-uuid'),
@@ -94,12 +95,7 @@ _.create_from_text = function createFromText(message, kwargs, callback) {
} else {
kwargs = kwargs || {};
}
- kwargs['message'] = message;
- kwargs['sentry.interfaces.Message'] = {
- message: message,
- params: []
- };
- var result = this.process(kwargs);
+ var result = this.process(parsers.parseText(message, kwargs));
callback && callback(result);
return result;
};
@@ -114,12 +110,8 @@ _.create_from_error = function createFromError(err, kwargs, callback) {
} else {
kwargs = kwargs || {};
}
- utils.parseStack(err.stack, function(e, frames) {
- kwargs['message'] = err.name+': '+err.message;
- kwargs['sentry.interfaces.Exception'] = {type:err.name, value:err.message};
- kwargs['sentry.interfaces.Stacktrace'] = {frames:frames};
- kwargs['culprit'] = err.name + ' in ' + err.stack.split('\n')[1].match(/^.*?\((.*?):\d+:\d+\)$/)[1].replace(process.cwd()+'/', '');
- var result = self.process(kwargs);
+ parsers.parseError(err, kwargs, function(kw) {
+ var result = self.process(kw);
callback && callback(result);
});
};
21 lib/parsers.js
View
@@ -0,0 +1,21 @@
+var utils = require('./utils');
+
+module.exports.parseText = function parseText(message, kwargs) {
+ kwargs = kwargs || {};
+ kwargs['message'] = message;
+ kwargs['sentry.interfaces.Message'] = {
+ message: message,
+ params: []
+ };
+ return kwargs;
+};
+
+module.exports.parseError = function parseError(err, kwargs, cb) {
+ utils.parseStack(err.stack, function(e, frames) {
+ kwargs['message'] = err.name+': '+(err.message || '<no message>');
+ kwargs['sentry.interfaces.Exception'] = {type:err.name, value:err.message};
+ kwargs['sentry.interfaces.Stacktrace'] = {frames:frames};
+ kwargs['culprit'] = (frames[0].filename || 'unknown file').replace(process.cwd()+'/', '')+':'+(frames[0]['function'] || 'unknown function');
+ cb(kwargs);
+ });
+};
Please sign in to comment.
Something went wrong with that request. Please try again.