Skip to content
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

fix: Handle the formatting of array arguments #1139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions src/utility.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var merge = require('./merge');

var RollbarJSON = {};

function setupJSON(polyfillJSON) {
if (isFunction(RollbarJSON.stringify) && isFunction(RollbarJSON.parse)) {
return;
Expand Down Expand Up @@ -450,6 +451,7 @@ function nonCircularClone(obj) {
}
return result;
}

return clone(obj, seen);
}

Expand Down Expand Up @@ -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;
Expand Down
31 changes: 24 additions & 7 deletions test/utility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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\')');
});
*/
});
Loading