diff --git a/plugins/errors.js b/plugins/errors.js index d617202e4..54d571537 100644 --- a/plugins/errors.js +++ b/plugins/errors.js @@ -252,6 +252,11 @@ if (!Array.isArray) { "BOOMR_plugins_errors_wrap" ]; + /** + * Maximum size, in characters, of stack to capture + */ + var MAX_STACK_SIZE = 5000; + /** * BoomerangError object * @@ -398,6 +403,10 @@ if (!Array.isArray) { // parse the stack if (error.stack) { + if (error.stack.length > MAX_STACK_SIZE) { + error.stack = error.stack.substr(0, MAX_STACK_SIZE); + } + frames = ErrorStackParser.parse(error); if (frames && frames.length) { if (error.generatedStack) { diff --git a/tests/page-templates/14-errors/21-max-stack.html b/tests/page-templates/14-errors/21-max-stack.html new file mode 100644 index 000000000..b18acb9d0 --- /dev/null +++ b/tests/page-templates/14-errors/21-max-stack.html @@ -0,0 +1,22 @@ +<%= header %> +<%= boomerangScript %> + + +<%= footer %> diff --git a/tests/page-templates/14-errors/21-max-stack.js b/tests/page-templates/14-errors/21-max-stack.js new file mode 100644 index 000000000..f6bbb7b97 --- /dev/null +++ b/tests/page-templates/14-errors/21-max-stack.js @@ -0,0 +1,30 @@ +/*eslint-env mocha*/ +/*global BOOMR_test,assert*/ + +describe("e2e/14-errors/21-max-stack", function() { + var tf = BOOMR.plugins.TestFramework; + var t = BOOMR_test; + var C = BOOMR.utils.Compression; + + it("Should have sent a single beacon", function(done) { + t.validateBeaconWasSent(done); + }); + + it("Should have put the err on the beacon", function() { + var b = tf.lastBeacon(); + assert.isDefined(b.err); + }); + + it("Should have had 1 error", function() { + var b = tf.lastBeacon(); + assert.equal(C.jsUrlDecompress(b.err).length, 1); + }); + + it("Should have had a stack with a max length of around 5000 chars", function() { + var b = tf.lastBeacon(); + var err = BOOMR.plugins.Errors.decompressErrors(C.jsUrlDecompress(b.err))[0]; + + // allow for some wiggle room in message length, but close to 5000 + assert.closeTo(err.stack.length, "a is not defined".length + 5000, 10, "stack: " + err.stack); + }); +});