From c43b536ae8a477f6f95443756a0c5850c0eb7cc7 Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Mon, 6 Oct 2014 09:51:28 -0700 Subject: [PATCH 1/3] Cant reliably run env coffee shebang. changed to node --- Gruntfile.coffee | 4 ++-- bin/uglify.coffee | 40 ---------------------------------------- bin/uglify.js | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 42 deletions(-) delete mode 100755 bin/uglify.coffee create mode 100755 bin/uglify.js diff --git a/Gruntfile.coffee b/Gruntfile.coffee index a1eb400cb9..e27317c7b5 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -165,8 +165,8 @@ module.exports = (grunt) -> grunt.registerTask "uglify", "Uglifies bugsnag.js", () -> exec = require("child_process").exec done = this.async() - child = exec "./bin/uglify.coffee", (error, stdout, stderr) -> - console.log("Error running uglify.coffee: " + error) if error? + child = exec "./bin/uglify.js", (error, stdout, stderr) -> + console.log("Error running uglify.js: " + error) if error? done(!error?) diff --git a/bin/uglify.coffee b/bin/uglify.coffee deleted file mode 100755 index 81a467a956..0000000000 --- a/bin/uglify.coffee +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env coffee -# -fs = require 'fs' -UglifyJS = require 'uglifyjs' -version = require('../package.json').version - -ast = UglifyJS.parse(fs.readFileSync('src/bugsnag.js').toString('utf8'), - filename: "bugsnag-#{version}.js" -) - -compressor = UglifyJS.Compressor( - warnings: false # A bucket-load of 'Boolean && always false' - global_defs: { - BUGSNAG_TESTING: undefined - } -) - -ast.figure_out_scope() -ast = ast.transform(compressor) - -ast.figure_out_scope() -ast.mangle_names() - -source_map = UglifyJS.SourceMap( - file: "bugsnag-#{version}.min.js", - root: 'https://d2wy8f7a9ursnm.cloudfront.net/' -) - -stream = UglifyJS.OutputStream( - source_map: source_map -) - -ast.print(stream) - -comment = "\n//# sourceMappingURL=//d2wy8f7a9ursnm.cloudfront.net/bugsnag-#{version}.min.map" - -fs.writeFileSync('dist/bugsnag.min.js', stream.toString()) -console.log "dist/bugsnag.min.js (v#{version})" -fs.writeFileSync('dist/bugsnag.min.map', source_map.toString()) -console.log "dist/bugsnag.min.map (v#{version})" diff --git a/bin/uglify.js b/bin/uglify.js new file mode 100755 index 0000000000..af0293bb42 --- /dev/null +++ b/bin/uglify.js @@ -0,0 +1,40 @@ +#!/usr/bin/env node + +fs = require('fs'); +UglifyJS = require('uglifyjs'); +version = require('../package.json').version; + +ast = UglifyJS.parse(fs.readFileSync('src/bugsnag.js').toString('utf8'), { + filename: "bugsnag-"+version+".js" +}); + +compressor = UglifyJS.Compressor({ + warnings: false, // A bucket-load of 'Boolean && always false' + global_defs: { + BUGSNAG_TESTING: undefined + } +}); + +ast.figure_out_scope() +ast = ast.transform(compressor); + +ast.figure_out_scope(); +ast.mangle_names(); + +source_map = UglifyJS.SourceMap({ + file: "bugsnag-"+version+".min.js", + root: 'https://d2wy8f7a9ursnm.cloudfront.net/' +}); + +stream = UglifyJS.OutputStream({ + source_map: source_map +}); + +ast.print(stream); + +comment = "\n//# sourceMappingURL=//d2wy8f7a9ursnm.cloudfront.net/bugsnag-"+version+".min.map" + +fs.writeFileSync('dist/bugsnag.min.js', stream.toString()); +console.log("dist/bugsnag.min.js (v"+version+")"); +fs.writeFileSync('dist/bugsnag.min.map', source_map.toString()); +console.log("dist/bugsnag.min.map (v"+version+")"); From da0dd270f3bf458a57dc48ac73e765633e600ca1 Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Mon, 6 Oct 2014 10:17:16 -0700 Subject: [PATCH 2/3] made docs about beforeNotify clearer and tests a little safer --- README.md | 12 ++++++++++-- test/test.bugsnag.js | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index da09d54921..ba682273b3 100644 --- a/README.md +++ b/README.md @@ -240,8 +240,7 @@ Bugsnag.appVersion = "2.0.14"; To have more fine grained control over what errors are sent to Bugsnag, you can implement a `beforeNotify` function. If you want to halt the notification completely, -return `false` from this function. You can also add metaData by editing the `metaData` -parameter. +return `false` from this function. ```javascript Bugsnag.beforeNotify = function(payload) { @@ -251,6 +250,15 @@ Bugsnag.beforeNotify = function(payload) { } ``` +You can modify the `payload` or `metaData` by editing the parameters. + +```javascript +Bugsnag.beforeNotify = function(payload, metaData) { + // Filter out sensitive information + payload.url = "http://redacted.com"; +} +``` + The `payload` parameter contains the error's `name`, `message`, `file` and `lineNumber` where available, as well as some additional fields that we either show on your Bugsnag dashboard, or use for grouping. diff --git a/test/test.bugsnag.js b/test/test.bugsnag.js index bc2b6dfa73..3465a3f52d 100644 --- a/test/test.bugsnag.js +++ b/test/test.bugsnag.js @@ -213,6 +213,7 @@ describe("Bugsnag", function () { Bugsnag.notifyException(new Error("Example error")); assert.equal(requestData().params.url, "http://redacted.com"); + assert(Bugsnag.testRequest.called, "Bugsnag.testRequest should have been called"); }); it("should contain 'warning' as the default severity", function () { From fd2116cfba614a60ba82a2d7f04756aae158cd32 Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Mon, 6 Oct 2014 10:19:57 -0700 Subject: [PATCH 3/3] add npm test script --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 56680debf7..b735a466b9 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,9 @@ "name": "bugsnag-js", "version": "2.4.3", "private": true, + "scripts": { + "test": "grunt test" + }, "main": "src/bugsnag.js", "devDependencies": { "grunt": "~0.4.2",