diff --git a/src/utility.js b/src/utility.js index 6cd034f7f..bd14c2b94 100644 --- a/src/utility.js +++ b/src/utility.js @@ -1,6 +1,7 @@ var merge = require('./merge'); var RollbarJSON = {}; + function setupJSON(polyfillJSON) { if (isFunction(RollbarJSON.stringify) && isFunction(RollbarJSON.parse)) { return; @@ -450,6 +451,7 @@ function nonCircularClone(obj) { } return result; } + return clone(obj, seen); } @@ -689,6 +691,18 @@ function formatArgsAsString(args) { for (i = 0, len = args.length; i < len; ++i) { arg = args[i]; switch (typeName(arg)) { + case 'array': + var trimLimit = 10; + var trimmedArgs = arg.slice(0, trimLimit); + var argsToFormat = + trimmedArgs.length === trimLimit + ? trimmedArgs.concat( + '...output trimmed to ' + trimLimit + ' items...', + ) + : trimmedArgs; + + arg = '[' + formatArgsAsString(argsToFormat) + ']'; + break; case 'object': arg = stringify(arg); arg = arg.error || arg.value; diff --git a/test/utility.test.js b/test/utility.test.js index f571f7438..0a5e3066e 100644 --- a/test/utility.test.js +++ b/test/utility.test.js @@ -902,6 +902,23 @@ describe('formatArgsAsString', function () { expect(result).to.eql('1 {"a":42}'); }); + + it('should handle arrays gracefully', function () { + var args = [1, [{ a: 42 }], [{ b: 43 }, null, 'foo', [1, 2]]]; + var result = _.formatArgsAsString(args); + + expect(result).to.eql('1 [{"a":42}] [{"b":43} null foo [1 2]]'); + }); + + it('should trim large arrays to the list of 10 items', function () { + var args = [1, [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]]; + var result = _.formatArgsAsString(args); + + expect(result).to.eql( + '1 [2 3 4 5 6 7 8 9 10 11 ...output trimmed to 10 items...]', + ); + }); + it('should handle strings', function () { var args = [1, 'foo']; var result = _.formatArgsAsString(args); @@ -915,12 +932,12 @@ describe('formatArgsAsString', function () { expect(result).to.eql(''); }); /* - * PhantomJS does not support Symbol yet - it('should handle symbols', function() { - var args = [1, Symbol('hello')]; - var result = _.formatArgsAsString(args); + * PhantomJS does not support Symbol yet + it('should handle symbols', function() { + var args = [1, Symbol('hello')]; + var result = _.formatArgsAsString(args); - expect(result).to.eql('1 symbol(\'hello\')'); - }); - */ + expect(result).to.eql('1 symbol(\'hello\')'); + }); + */ });