From 52833ef26e34ebe70433ce57715359f7a4f9a1f8 Mon Sep 17 00:00:00 2001 From: Daniel Wylie Date: Wed, 27 Jan 2016 13:55:33 +1300 Subject: [PATCH 1/4] Add option to turn off humanise --- lib/raygun.js | 5 +++-- lib/raygun.messageBuilder.js | 2 +- test/raygun.messageBuilder_test.js | 23 ++++++++++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/raygun.js b/lib/raygun.js index 520a135..f1ad2b0 100644 --- a/lib/raygun.js +++ b/lib/raygun.js @@ -15,7 +15,7 @@ var MessageBuilder = require('./raygun.messageBuilder'); var OfflineStorage = require('./raygun.offline'); var Raygun = function () { - var _apiKey, _filters, raygun = this, _user, _version, _host, _port, _useSSL, _onBeforeSend, _offlineStorage, _isOffline, _offlineStorageOptions, _groupingKey, _tags; + var _apiKey, _filters, raygun = this, _user, _version, _host, _port, _useSSL, _onBeforeSend, _offlineStorage, _isOffline, _offlineStorageOptions, _groupingKey, _tags, _useHumanStringForObject; raygun.init = function (options) { _apiKey = options.apiKey; @@ -29,6 +29,7 @@ var Raygun = function () { _isOffline = options.isOffline; _groupingKey = options.groupingKey; _tags = options.tags; + _useHumanStringForObject = options.useHumanStringForObject || true; if (_isOffline) { _offlineStorage.init(_offlineStorageOptions); @@ -88,7 +89,7 @@ var Raygun = function () { mergedTags = mergedTags.concat(tags); } - var builder = new MessageBuilder({filters: _filters}) + var builder = new MessageBuilder({filters: _filters, useHumanStringForObject: _useHumanStringForObject}) .setErrorDetails(exception) .setRequestDetails(request) .setMachineName() diff --git a/lib/raygun.messageBuilder.js b/lib/raygun.messageBuilder.js index e0c98a1..6e30615 100644 --- a/lib/raygun.messageBuilder.js +++ b/lib/raygun.messageBuilder.js @@ -52,7 +52,7 @@ var RaygunMessageBuilder = function (options) { this.setErrorDetails = function (error) { var errorType = Object.prototype.toString.call(error); - if (errorType === '[object Object]') { + if (errorType === '[object Object]' && options.useHumanStringForObject) { error = humanString(error); message.details.groupingKey = error.replace(/\W+/g, "").substring(0, 64); } diff --git a/test/raygun.messageBuilder_test.js b/test/raygun.messageBuilder_test.js index 03cfdb1..6bb7f2d 100644 --- a/test/raygun.messageBuilder_test.js +++ b/test/raygun.messageBuilder_test.js @@ -45,7 +45,28 @@ test('basic builder tests', function (t) { tt.ok(message.details.machineName); tt.end(); }); - + + t.test('humanise error string', function (tt){ + var builder = new MessageBuilder({ useHumanStringForObject:true }); + builder.setErrorDetails({name:'Test'}); + + var message = builder.build(); + tt.ok(message.details.error.message); + tt.equal('name=Test', message.details.error.message); + tt.ok(message.details.groupingKey); + tt.end(); + }); + + t.test('dont humanise string', function (tt){ + var builder = new MessageBuilder({useHumanStringForObject:false}); + builder.setErrorDetails({name:'Test'}); + + var message = builder.build(); + tt.notOk(message.details.groupingKey); + tt.equal('NoMessage', message.details.error.message); + tt.end(); + }); + t.end(); }); From 8617e19021d48d2e317c80f1f80d86522eadb270 Mon Sep 17 00:00:00 2001 From: Daniel Wylie Date: Wed, 27 Jan 2016 13:56:04 +1300 Subject: [PATCH 2/4] Bump version --- package.json | 2 +- test/raygun.messageBuilder_test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a11f2df..b22b489 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "raygun", "description": "Raygun.io plugin for Node", - "version": "0.8.4", + "version": "0.8.5", "homepage": "https://github.com/MindscapeHQ/raygun4node", "author": { "name": "MindscapeHQ", diff --git a/test/raygun.messageBuilder_test.js b/test/raygun.messageBuilder_test.js index 6bb7f2d..1a9a286 100644 --- a/test/raygun.messageBuilder_test.js +++ b/test/raygun.messageBuilder_test.js @@ -63,7 +63,7 @@ test('basic builder tests', function (t) { var message = builder.build(); tt.notOk(message.details.groupingKey); - tt.equal('NoMessage', message.details.error.message); + tt.equal('NoMessage', message.details.error.message); tt.end(); }); From 7bec7bd54c3da737f54c5c60a467883419674ead Mon Sep 17 00:00:00 2001 From: Daniel Wylie Date: Wed, 27 Jan 2016 14:01:46 +1300 Subject: [PATCH 3/4] Pick property properly --- lib/raygun.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/raygun.js b/lib/raygun.js index f1ad2b0..5c151b9 100644 --- a/lib/raygun.js +++ b/lib/raygun.js @@ -29,7 +29,7 @@ var Raygun = function () { _isOffline = options.isOffline; _groupingKey = options.groupingKey; _tags = options.tags; - _useHumanStringForObject = options.useHumanStringForObject || true; + _useHumanStringForObject = options.useHumanStringForObject === undefined ? true : options.useHumanStringForObject; if (_isOffline) { _offlineStorage.init(_offlineStorageOptions); From 880baf919f0dbb95215316ab79e5673f64c58e87 Mon Sep 17 00:00:00 2001 From: Daniel Wylie Date: Wed, 27 Jan 2016 14:05:14 +1300 Subject: [PATCH 4/4] Update read --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 41103be..5faa577 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,17 @@ When initializing Raygun, pass through a `groupingKey` function. } }); +### Custom error objects + +By default Raygun4Node tries to convert unknown objects into a human readable string to help with grouping, this doens't always make sense. + +To disable it + + var raygunClient = new raygun.Client().init({ + apiKey: 'YOUR_KEY', + useHumanStringForObject: false + }); + ### Examples View a screencast on creating an app with Node.js and Express.js, then hooking up the error handling and sending them at [http://raygun.io/blog/2013/07/video-nodejs-error-handling-with-raygun/](http://raygun.io/blog/2013/07/video-nodejs-error-handling-with-raygun/) @@ -223,6 +234,7 @@ In lieu of a formal styleguide, take care to maintain the existing coding style. ## Release History +- 0.8.5 - Add ability to turn off 'humanised-object-strings' - 0.8.4 - Add some smarts around passing an object in to the exception parameter - 0.8.3 - Turn strings into errors if passed through. Log out request errors. - 0.8.2 - Add setTags method