Comparing version 1.0.1 to 1.0.2
@@ -5,2 +5,7 @@ # Airbrake Changelog | ||
### [v1.0.2][v1.0.2] (May 26, 2016) | ||
* Change notifier name from `airbrake` to `node-airbrake` | ||
([#96](https://github.com/airbrake/node-airbrake/pull/96)) | ||
### [v1.0.1][v1.0.1] (April 5, 2016) | ||
@@ -58,1 +63,2 @@ | ||
[v1.0.1]: https://github.com/airbrake/node-airbrake/releases/tag/v1.0.1 | ||
[v1.0.2]: https://github.com/airbrake/node-airbrake/releases/tag/v1.0.2 |
@@ -7,6 +7,4 @@ var HTTP_STATUS_CODES = require('http').STATUS_CODES; | ||
var request = require('request'); | ||
var xmlbuilder = require('xmlbuilder'); | ||
var stackTrace = require('stack-trace'); | ||
var _ = require('lodash'); | ||
var querystring = require('querystring'); | ||
var stringify = require('json-stringify-safe'); | ||
@@ -32,3 +30,3 @@ var execSync = require('sync-exec'); | ||
this.protocol = 'https'; | ||
this.serviceHost = process.env.AIRBRAKE_SERVER || 'api.airbrake.io'; | ||
this.serviceHost = process.env.AIRBRAKE_SERVER || 'api.airbrake.io'; | ||
this.requestOptions = {}; | ||
@@ -55,8 +53,8 @@ this.ignoredExceptions = []; | ||
Airbrake.PACKAGE = (function() { | ||
Airbrake.PACKAGE = (function () { | ||
var json = fs.readFileSync(__dirname + '/../package.json', 'utf8'); | ||
return JSON.parse(json); | ||
})(); | ||
}()); | ||
Airbrake.createClient = function(projectId, key, env) { | ||
Airbrake.createClient = function (projectId, key, env) { | ||
var instance = new this(); | ||
@@ -69,7 +67,7 @@ instance.key = key; | ||
Airbrake.prototype.expressHandler = function(disableUncaughtException) { | ||
Airbrake.prototype.expressHandler = function (disableUncaughtException) { | ||
var self = this; | ||
if(!disableUncaughtException) { | ||
process.on('uncaughtException', function(err) { | ||
if (!disableUncaughtException) { | ||
process.on('uncaughtException', function (err) { | ||
self._onError(err, true); | ||
@@ -80,11 +78,15 @@ }); | ||
return function errorHandler(err, req, res, next) { | ||
if (res.statusCode < 400) res.statusCode = 500; | ||
var error = err; | ||
var requestObj = req; | ||
var responseObj = res; | ||
err.url = req.url; | ||
err.component = req.url; | ||
err.action = req.method; | ||
err.params = req.body; | ||
err.session = req.session; | ||
err.ua = req.get('User-Agent'); | ||
if (responseObj.statusCode < 400) responseObj.statusCode = 500; | ||
error.url = requestObj.url; | ||
error.component = requestObj.url; | ||
error.action = requestObj.method; | ||
error.params = requestObj.body; | ||
error.session = requestObj.session; | ||
error.ua = requestObj.get('User-Agent'); | ||
self._onError(err, false); | ||
@@ -95,11 +97,9 @@ next(err); | ||
Airbrake.prototype._onError = function(err, die) { | ||
Airbrake.prototype._onError = function (err, die) { | ||
var self = this; | ||
if (!(err instanceof Error)) { | ||
err = new Error(err); | ||
} | ||
var error = (err instanceof Error) ? err : new Error(err); | ||
self.log('Airbrake: Uncaught exception, sending notification for:'); | ||
self.log(err.stack || err); | ||
self.log(error.stack || error); | ||
self.notify(err, function(notifyErr, url, devMode) { | ||
self.notify(error, function (notifyErr, notifyUrl, devMode) { | ||
if (notifyErr) { | ||
@@ -111,3 +111,3 @@ self.log('Airbrake: Could not notify service.'); | ||
} else { | ||
self.log('Airbrake: Notified service: ' + url); | ||
self.log('Airbrake: Notified service: ' + notifyUrl); | ||
} | ||
@@ -121,17 +121,17 @@ | ||
Airbrake.prototype.handleExceptions = function(die) { | ||
Airbrake.prototype.handleExceptions = function (die) { | ||
var self = this; | ||
if (typeof die === 'undefined') { | ||
die = true; | ||
} | ||
process.on('uncaughtException', function(err) { | ||
self._onError(err, die); | ||
var shouldDie = (typeof die === 'undefined') ? true : die; | ||
process.on('uncaughtException', function (err) { | ||
self._onError(err, shouldDie); | ||
}); | ||
}; | ||
Airbrake.prototype.log = function(str) { | ||
if(this.consoleLogError) console.error(str); | ||
Airbrake.prototype.log = function (str) { | ||
if (this.consoleLogError) { | ||
console.error(str); | ||
} | ||
}; | ||
Airbrake.prototype._sendRequest = function(err, cb) { | ||
Airbrake.prototype._sendRequest = function (err, cb) { | ||
var callback = this._callback(cb); | ||
@@ -149,12 +149,12 @@ | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json', | ||
}, | ||
Accept: 'application/json' | ||
} | ||
}, this.requestOptions); | ||
request(options, function(err, res, body) { | ||
if (err) { | ||
request(options, function (requestErr, res, responseBody) { | ||
if (requestErr) { | ||
return callback(err); | ||
} | ||
if (undefined === body) { | ||
if (typeof responseBody === 'undefined') { | ||
return callback(new Error('invalid body')); | ||
@@ -166,6 +166,6 @@ } | ||
var explanation = body.match(/<error>([^<]+)/i); | ||
var explanation = responseBody.match(/<error>([^<]+)/i); | ||
explanation = (explanation) | ||
? ': ' + explanation[1] | ||
: ': ' + body; | ||
: ': ' + responseBody; | ||
@@ -177,22 +177,22 @@ return callback(new Error( | ||
var url = JSON.parse(body).url; | ||
callback(null, url); | ||
return callback(null, JSON.parse(responseBody).url); | ||
}); | ||
} | ||
}; | ||
Airbrake.prototype.notify = function(err, cb) { | ||
Airbrake.prototype.notify = function (err, cb) { | ||
var callback = this._callback(cb); | ||
var exit = false; | ||
// log errors instead of posting to airbrake if a dev enviroment | ||
if (this.developmentEnvironments.indexOf(this.env) != -1) { | ||
if (this.developmentEnvironments.indexOf(this.env) !== -1) { | ||
this.log(err); | ||
return callback(null, null, true); | ||
} | ||
this.ignoredExceptions.forEach(function(exception){ | ||
if (err instanceof exception){ | ||
this.ignoredExceptions.forEach(function (exception) { | ||
if (err instanceof exception) { | ||
exit = true; | ||
} | ||
}) | ||
}); | ||
if (exit){ | ||
if (exit) { | ||
return callback(null, null, false); | ||
@@ -204,5 +204,5 @@ } | ||
Airbrake.prototype._callback = function(cb) { | ||
Airbrake.prototype._callback = function (cb) { | ||
var self = this; | ||
return function(err) { | ||
return function (err) { | ||
if (cb) { | ||
@@ -219,7 +219,7 @@ cb.apply(self, arguments); | ||
Airbrake.prototype.url = function(path) { | ||
Airbrake.prototype.url = function (path) { | ||
return this.protocol + '://' + this.serviceHost + path; | ||
}; | ||
Airbrake.prototype.environmentJSON = function(err){ | ||
Airbrake.prototype.environmentJSON = function (err) { | ||
var cgiData = {}; | ||
@@ -229,24 +229,24 @@ var self = this; | ||
if (this.whiteListKeys.length > 0) { | ||
Object.keys(process.env).forEach(function(key) { | ||
Object.keys(process.env).forEach(function (key) { | ||
if (self.whiteListKeys.indexOf(key) > -1) { | ||
cgiData[key] = process.env[key]; | ||
} else { | ||
cgiData[key] = "[FILTERED]"; | ||
cgiData[key] = '[FILTERED]'; | ||
} | ||
}) | ||
}); | ||
} else if (this.blackListKeys.length > 0) { | ||
Object.keys(process.env).forEach(function(key) { | ||
if (self.blackListKeys.indexOf(key) > -1 ) { | ||
cgiData[key] = "[FILTERED]"; | ||
Object.keys(process.env).forEach(function (key) { | ||
if (self.blackListKeys.indexOf(key) > -1) { | ||
cgiData[key] = '[FILTERED]'; | ||
} else { | ||
cgiData[key] = process.env[key]; | ||
} | ||
}) | ||
}); | ||
} | ||
if (err.ua){ | ||
if (err.ua) { | ||
cgiData.HTTP_USER_AGENT = err.ua; | ||
} | ||
Object.keys(err).forEach(function(key) { | ||
Object.keys(err).forEach(function (key) { | ||
if (self.exclude.indexOf(key) >= 0) { | ||
@@ -261,3 +261,3 @@ return; | ||
if(os.platform() != "win32") { | ||
if (os.platform() !== 'win32') { | ||
// this two properties are *NIX only | ||
@@ -279,42 +279,44 @@ cgiData['process.uid'] = process.getuid(); | ||
Airbrake.prototype.contextJSON = function(err){ | ||
Airbrake.prototype.contextJSON = function (err) { | ||
var context = {}; | ||
context["notifier"] = { | ||
name: Airbrake.PACKAGE.name, | ||
context.notifier = { | ||
name: 'node-airbrake', | ||
version: Airbrake.PACKAGE.version, | ||
url: Airbrake.PACKAGE.homepage | ||
}; | ||
context["environment"] = this.env; | ||
context["rootDirectory"] = this.projectRoot; | ||
context["os"] = os.type(); | ||
context["hostname"] = os.hostname(); | ||
context["url"] = url.resolve(this.host, err.url || ''); | ||
context.environment = this.env; | ||
context.rootDirectory = this.projectRoot; | ||
context.os = os.type(); | ||
context.hostname = os.hostname(); | ||
context.url = url.resolve(this.host, err.url || ''); | ||
return context; | ||
}; | ||
Airbrake.prototype.notifyJSON = function(err){ | ||
Airbrake.prototype.notifyJSON = function (err) { | ||
var trace = stackTrace.parse(err); | ||
var self = this; | ||
return stringify({ | ||
"errors": [ | ||
errors: [ | ||
{ | ||
type: err.type || "Error", | ||
type: err.type || 'Error', | ||
message: err.message, | ||
backtrace: trace.map(function(callSite){ | ||
backtrace: trace.map(function (callSite) { | ||
return { | ||
"file": callSite.getFileName() || "", | ||
"line": callSite.getLineNumber(), | ||
"function": callSite.getFunctionName() || "" | ||
file: callSite.getFileName() || '', | ||
line: callSite.getLineNumber(), | ||
function: callSite.getFunctionName() || '' | ||
}; | ||
}), | ||
}) | ||
}], | ||
environment: this.environmentJSON(err), | ||
context: this.contextJSON(err), | ||
session: this.sessionVars(err), | ||
params: this.paramsVars(err) | ||
environment: self.environmentJSON(err), | ||
context: self.contextJSON(err), | ||
session: self.sessionVars(err), | ||
params: self.paramsVars(err) | ||
}); | ||
}; | ||
Airbrake.prototype.sessionVars = function(err) { | ||
return (typeof err.session === 'object') | ||
Airbrake.prototype.sessionVars = function (err) { | ||
return (typeof err.session === 'object') | ||
? err.session | ||
@@ -324,3 +326,3 @@ : {}; | ||
Airbrake.prototype.paramsVars = function(err) { | ||
Airbrake.prototype.paramsVars = function (err) { | ||
return (typeof err.params === 'object') | ||
@@ -331,19 +333,24 @@ ? err.params | ||
Airbrake.prototype.trackDeployment = function(params, cb) { | ||
if (typeof params === 'function') { | ||
cb = params; | ||
params = {}; | ||
Airbrake.prototype.trackDeployment = function (params, cb) { | ||
var callback = cb; | ||
var deploymentParams = params || {}; | ||
if (typeof deploymentParams === 'function') { | ||
callback = deploymentParams; | ||
deploymentParams = {}; | ||
} | ||
params = params || {}; | ||
params = _.merge({ | ||
var getCommandValue = function (command) { | ||
return command.stdout.toString().slice(0, -1); | ||
}; | ||
deploymentParams = _.merge({ | ||
key: this.key, | ||
env: this.env, | ||
user: process.env.USER, | ||
rev: execSync('git rev-parse HEAD').stdout.toString().slice(0, -1), | ||
repo: execSync('git config --get remote.origin.url').stdout. | ||
toString().slice(0, -1), | ||
}, params); | ||
rev: getCommandValue(execSync('git rev-parse HEAD')), | ||
repo: getCommandValue(execSync('git config --get remote.origin.url')) | ||
}, deploymentParams); | ||
var body = this.deploymentPostData(params); | ||
var body = this.deploymentPostData(deploymentParams); | ||
@@ -357,3 +364,3 @@ var options = _.merge({ | ||
'Content-Length': body.length, | ||
'Content-Type': 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
@@ -363,7 +370,7 @@ proxy: this.proxy | ||
var callback = this._callback(cb); | ||
var requestCallback = this._callback(callback); | ||
request(options, function(err, res, body) { | ||
request(options, function (err, res, responseBody) { | ||
if (err) { | ||
return callback(err); | ||
return requestCallback(err); | ||
} | ||
@@ -373,18 +380,18 @@ | ||
var status = HTTP_STATUS_CODES[res.statusCode]; | ||
return callback(new Error( | ||
'Deployment failed: ' + res.statusCode + ' ' + status + ': ' + body | ||
return requestCallback(new Error( | ||
'Deployment failed: ' + res.statusCode + ' ' + status + ': ' + responseBody | ||
)); | ||
} | ||
callback(null, params); | ||
return requestCallback(null, deploymentParams); | ||
}); | ||
}; | ||
Airbrake.prototype.deploymentPostData = function(params) { | ||
Airbrake.prototype.deploymentPostData = function (params) { | ||
return JSON.stringify({ | ||
'version': 'v2.0', | ||
'environment': params.env, | ||
'username': params.user, | ||
'revision': params.rev, | ||
'repository': params.repo | ||
version: 'v2.0', | ||
environment: params.env, | ||
username: params.user, | ||
revision: params.rev, | ||
repository: params.repo | ||
}); | ||
@@ -391,0 +398,0 @@ }; |
@@ -20,3 +20,3 @@ { | ||
"description": "Node.js client for airbrake.io", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"homepage": "https://github.com/airbrake/node-airbrake", | ||
@@ -32,3 +32,5 @@ "repository": { | ||
"scripts": { | ||
"test": "nsp check && test/run.js" | ||
"lint": "eslint .", | ||
"test": "nsp check && test/run.js", | ||
"posttest": "npm run lint" | ||
}, | ||
@@ -40,6 +42,8 @@ "dependencies": { | ||
"stack-trace": "~0.0.6", | ||
"sync-exec": "^0.6.2", | ||
"xmlbuilder": "~0.4.2" | ||
"sync-exec": "^0.6.2" | ||
}, | ||
"devDependencies": { | ||
"eslint": "~2.8.0", | ||
"eslint-config-airbnb-base": "~1.0.3", | ||
"eslint-plugin-import": "~1.6.1", | ||
"express": "~4.13.4", | ||
@@ -49,3 +53,2 @@ "far": "~0.0.4", | ||
"nsp": "~2.2.0", | ||
"semver": "*", | ||
"sinon": "~1.7.2" | ||
@@ -52,0 +55,0 @@ }, |
@@ -0,1 +1,5 @@ | ||
// Ignore rules for initialization file. | ||
/* eslint global-require: 0 */ | ||
/* eslint import/no-unresolved: 0 */ | ||
var path = require('path'); | ||
@@ -11,3 +15,3 @@ var _ = require('lodash'); | ||
_.merge(exports, require('./config')); | ||
} catch (e) {} | ||
} catch (e) { console.log(e); } | ||
@@ -19,3 +23,3 @@ exports.port = 8424; | ||
root: root, | ||
lib: root + '/lib', | ||
lib: root + '/lib' | ||
}; |
@@ -5,4 +5,6 @@ var common = require('../common'); | ||
var Airbrake = require(common.dir.root); | ||
(function testAddingKeyToDevelopmentEnvironments() { | ||
var airbrake = require(common.dir.root).createClient(null, common.key, 'dev'); | ||
var airbrake = Airbrake.createClient(null, common.key, 'dev'); | ||
airbrake.developmentEnvironments.push('dev'); | ||
@@ -15,6 +17,6 @@ sinon.stub(airbrake, '_sendRequest'); | ||
airbrake._sendRequest.restore(); | ||
})(); | ||
}()); | ||
(function testDevelopmentEnviroment() { | ||
var airbrake = require(common.dir.root).createClient(null, common.key, 'dev'); | ||
var airbrake = Airbrake.createClient(null, common.key, 'dev'); | ||
sinon.stub(airbrake, '_sendRequest'); | ||
@@ -28,6 +30,6 @@ | ||
airbrake._sendRequest.restore(); | ||
})(); | ||
}()); | ||
(function testProductionEnviroment() { | ||
var airbrake = require(common.dir.root).createClient(null, common.key, 'production'); | ||
var airbrake = Airbrake.createClient(null, common.key, 'production'); | ||
sinon.stub(airbrake, '_sendRequest'); | ||
@@ -39,2 +41,2 @@ | ||
airbrake._sendRequest.restore(); | ||
})(); | ||
}()); |
@@ -13,3 +13,3 @@ var express = require('express'); | ||
app.get('/caught', function(req, res, next) { | ||
app.get('/caught', function (req, res, next) { | ||
var err = new Error('i am caught!'); | ||
@@ -19,3 +19,3 @@ next(err); | ||
app.get('/uncaught', function(req, res, next) { | ||
app.get('/uncaught', function () { | ||
// This actually gets handled by app.error() as well, express will catch | ||
@@ -29,11 +29,18 @@ // this one for us. | ||
http.request({port: common.port, path: '/caught', headers: { | ||
"User-Agent": "foo" | ||
}}, function() { | ||
assert.equal(airbrake._onError.getCall(0).args[0].ua, 'foo') | ||
assert.equal(airbrake._onError.callCount, 1); | ||
http.request({port: common.port, path: '/uncaught'}, function () { | ||
assert.equal(airbrake._onError.callCount, 2); | ||
process.exit() | ||
}).end(); | ||
http.request({ | ||
port: common.port, | ||
path: '/caught', | ||
headers: { | ||
'User-Agent': 'foo' | ||
} | ||
}, function () { | ||
assert.equal(airbrake._onError.getCall(0).args[0].ua, 'foo'); | ||
assert.equal(airbrake._onError.callCount, 1); | ||
http.request({ | ||
port: common.port, | ||
path: '/uncaught' | ||
}, function () { | ||
assert.equal(airbrake._onError.callCount, 2); | ||
process.exit(); | ||
}).end(); | ||
}).end(); |
@@ -42,3 +42,3 @@ var common = require('../common'); | ||
airbrake.log.restore(); | ||
})(); | ||
}()); | ||
@@ -57,3 +57,3 @@ (function testNotifyError() { | ||
process.exit.restore(); | ||
})(); | ||
}()); | ||
@@ -63,3 +63,3 @@ airbrake.log.restore(); | ||
process.on.restore(); | ||
})(); | ||
}()); | ||
@@ -85,2 +85,2 @@ (function testDoNotKillProcessAfterUnhandledException() { | ||
process.on.restore(); | ||
})(); | ||
}()); |
var common = require('../common'); | ||
var airbrake = require(common.dir.root).createClient() | ||
var airbrake = require(common.dir.root).createClient(); | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
var os = require('os'); | ||
var xmlbuilder = require('xmlbuilder'); | ||
(function testDefaultHost() { | ||
assert.equal(airbrake.host, 'https://' + os.hostname()); | ||
})(); | ||
}()); | ||
(function testPlainHost() { | ||
var err = new Error('oh no'); | ||
var url = airbrake.contextJSON(err)["url"]; | ||
assert.equal(url, airbrake.host.toLowerCase() + "/"); | ||
})(); | ||
var url = airbrake.contextJSON(err).url; | ||
assert.equal(url, airbrake.host.toLowerCase() + '/'); | ||
}()); | ||
@@ -21,6 +19,6 @@ (function testPartialErrUrl() { | ||
err.url = '/foo'; | ||
var url = airbrake.contextJSON(err)["url"]; | ||
var url = airbrake.contextJSON(err).url; | ||
assert.equal(url, airbrake.host.toLowerCase() + err.url); | ||
})(); | ||
}()); | ||
@@ -30,5 +28,5 @@ (function testAbsoluteErrUrl() { | ||
err.url = 'http://example.org/bar'; | ||
var url = airbrake.contextJSON(err)["url"]; | ||
var url = airbrake.contextJSON(err).url; | ||
assert.equal(url, err.url); | ||
})(); | ||
}()); |
var common = require('../common'); | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
var Airbrake = require(common.dir.root); | ||
function MyError(){ | ||
function MyError() { | ||
var temp = Error.apply(this, arguments); | ||
temp.name = this.name = 'MyError'; | ||
this.stack = temp.stack; | ||
this.message = temp.message | ||
this.message = temp.message; | ||
} | ||
MyError.prototype = Object.create(Error.prototype, { | ||
@@ -18,3 +20,3 @@ constructor: { | ||
(function testAddingExceptionToIgnoredExceptions() { | ||
var airbrake = require(common.dir.root).createClient(null, common.key, 'production'); | ||
var airbrake = Airbrake.createClient(null, common.key, 'production'); | ||
airbrake.ignoredExceptions.push(MyError); | ||
@@ -28,2 +30,2 @@ | ||
airbrake._sendRequest.restore(); | ||
})(); | ||
}()); |
var common = require('../common'); | ||
var airbrake = require(common.dir.root).createClient() | ||
var airbrake = require(common.dir.root).createClient(); | ||
var assert = require('assert'); | ||
var xmlbuilder = require('xmlbuilder'); | ||
var os = require('os'); | ||
@@ -15,3 +13,3 @@ (function testSettingCustomExclusions() { | ||
assert(!cgiData['err.domain']); | ||
})(); | ||
}()); | ||
@@ -32,3 +30,3 @@ (function testCgiDataFromProcessEnv() { | ||
assert.equal(typeof cgiData['os.uptime'], 'number'); | ||
})(); | ||
}()); | ||
@@ -41,44 +39,44 @@ (function testCustomErrorProperties() { | ||
assert.equal(cgiData['err.myKey'], err.myKey); | ||
})(); | ||
}()); | ||
(function testWhitelistKeys(){ | ||
(function testWhitelistKeys() { | ||
var err = new Error(); | ||
err.myKey = 'some value'; | ||
airbrake.whiteListKeys.push("PWD"); | ||
airbrake.whiteListKeys.push('PWD'); | ||
var cgiData = airbrake.environmentJSON(err); | ||
assert.equal(typeof cgiData['PWD'], 'string'); | ||
assert.equal(cgiData['PATH'], '[FILTERED]'); | ||
assert.equal(typeof cgiData.PWD, 'string'); | ||
assert.equal(cgiData.PATH, '[FILTERED]'); | ||
airbrake.whiteListKeys = []; | ||
})(); | ||
}()); | ||
(function testBlacklistKeys(){ | ||
(function testBlacklistKeys() { | ||
var err = new Error(); | ||
err.myKey = 'some value'; | ||
airbrake.blackListKeys.push("PWD"); | ||
airbrake.blackListKeys.push('PWD'); | ||
var cgiData = airbrake.environmentJSON(err); | ||
assert.equal(cgiData['PWD'], '[FILTERED]'); | ||
assert.equal(typeof cgiData['PATH'], 'string'); | ||
airbrake.blackListKeys = [] | ||
})(); | ||
assert.equal(cgiData.PWD, '[FILTERED]'); | ||
assert.equal(typeof cgiData.PATH, 'string'); | ||
airbrake.blackListKeys = []; | ||
}()); | ||
(function testSessionVars() { | ||
var err = new Error(); | ||
err.session = {foo: 'bar'}; | ||
err.session = { foo: 'bar' }; | ||
var session = airbrake.sessionVars(err); | ||
assert.deepEqual(session, err.session); | ||
})(); | ||
}()); | ||
(function testParamsVars() { | ||
var err = new Error(); | ||
err.params = {foo: 'bar'}; | ||
err.params = { foo: 'bar' }; | ||
var params = airbrake.paramsVars(err); | ||
assert.deepEqual(params, err.params); | ||
})(); | ||
}()); | ||
(function testCircularVars() { | ||
var vars = {foo: 'bar', circular: {}}; | ||
var vars = { foo: 'bar', circular: {} }; | ||
vars.circular.self = vars.circular; | ||
@@ -90,6 +88,5 @@ var err = new Error(); | ||
airbrake.notifyJSON(err); | ||
})(); | ||
}()); | ||
(function testAppendErrorXmlWithBadStack() { | ||
var notice = xmlbuilder.create().begin('notice'); | ||
var err = new Error('oh oh'); | ||
@@ -99,3 +96,3 @@ | ||
airbrake.notifyJSON(err); | ||
})(); | ||
}()); | ||
@@ -108,2 +105,2 @@ (function testEmptyErrorMessageDoesNotProduceInvalidXml() { | ||
assert.ok(!/<\/>/.test(xml)); | ||
})(); | ||
}()); |
@@ -6,5 +6,5 @@ #!/usr/bin/env node | ||
var specificTest = process.argv[2] | ||
if (undefined !== specificTest && 'all' !== specificTest) { | ||
far.include(new RegExp('test-' + specificTest + '\.js$')); | ||
var specificTest = process.argv[2]; | ||
if (typeof specificTest !== 'undefined' && specificTest !== 'all') { | ||
far.include(new RegExp('test-' + specificTest + '.js$')); | ||
} else { | ||
@@ -15,13 +15,13 @@ far.include(/test-.*\.js$/); | ||
var verbosity = process.argv[3] | ||
if (undefined !== verbosity) { | ||
verbosity = Number(verbosity) | ||
if (1 !== verbosity && 2 !== verbosity) { | ||
console.log('Please provide a verbosity value of 1 or 2') | ||
process.exit(1) | ||
var verbosity = process.argv[3]; | ||
if (typeof verbosity !== 'undefined') { | ||
verbosity = Number(verbosity); | ||
if (verbosity !== 1 && verbosity !== 2) { | ||
console.log('Please provide a verbosity value of 1 or 2'); | ||
process.exit(1); | ||
} | ||
far.verbose(verbosity) | ||
} | ||
far.verbose(verbosity); | ||
} | ||
far.execute(); |
@@ -1,5 +0,5 @@ | ||
var mockery = require('mockery'), | ||
sinon = require('sinon'), | ||
common = require('../common'), | ||
assert = require('assert'); | ||
var mockery = require('mockery'); | ||
var sinon = require('sinon'); | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
@@ -11,3 +11,3 @@ mockery.enable({ | ||
var requestStub = sinon.stub() | ||
var requestStub = sinon.stub(); | ||
@@ -23,3 +23,3 @@ mockery.registerMock('request', requestStub); | ||
airbrake.notify(new Error('the error'), function() {}); | ||
airbrake.notify(new Error('the error'), function () {}); | ||
@@ -41,4 +41,4 @@ assert(requestStub.calledWith( | ||
repo: Airbrake.PACKAGE.repository.url, | ||
rev: '98103a8fa850d5eaf3666e419d8a0a93e535b1b2', | ||
}, function() {}); | ||
rev: '98103a8fa850d5eaf3666e419d8a0a93e535b1b2' | ||
}, function () {}); | ||
@@ -45,0 +45,0 @@ assert(requestStub.calledWith( |
@@ -6,3 +6,3 @@ var common = require('../common'); | ||
var server = http.createServer(function(req, res) { | ||
var server = http.createServer(function (req, res) { | ||
res.writeHead(500); | ||
@@ -12,19 +12,19 @@ res.end('something went wrong'); | ||
server.listen(common.port, function() { | ||
var err = new Error('test-notify'); | ||
server.listen(common.port, function () { | ||
var testNotifyError = new Error('test-notify'); | ||
airbrake.serviceHost = 'localhost:' + common.port; | ||
airbrake.protocol = 'http'; | ||
var errorProcessed = false; | ||
var errorTimeout = setTimeout(function () { | ||
errorTimeout = null | ||
errorTimeout = null; | ||
if (!errorProcessed) { | ||
assert.ok(false, 'should have processed error before timeout of 5s') | ||
assert.ok(false, 'should have processed error before timeout of 5s'); | ||
} | ||
}, 5000) | ||
}, 5000); | ||
var errorProcessed = false; | ||
airbrake.on('error', function (err) { | ||
errorProcessed = true | ||
if (null !== errorTimeout) { | ||
errorProcessed = true; | ||
if (errorTimeout !== null) { | ||
clearTimeout(errorTimeout); | ||
@@ -38,3 +38,3 @@ } | ||
airbrake.notify(err); | ||
airbrake.notify(testNotifyError); | ||
}); |
var common = require('../common'); | ||
var airbrake = require(common.dir.root).createClient(null, common.key); | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
@@ -11,3 +10,3 @@ | ||
process.on('exit', function() { | ||
process.on('exit', function () { | ||
var exitCode = (airbrake.notify.called) | ||
@@ -21,2 +20,1 @@ ? 0 | ||
throw err; | ||
@@ -6,5 +6,5 @@ var common = require('../common'); | ||
var myErr = new Error('test-notify'); | ||
airbrake.notify(myErr, function(err) { | ||
assert.ok(!!err, 'should receive an error object') | ||
airbrake.notify(myErr, function (err) { | ||
assert.ok(!!err, 'should receive an error object'); | ||
assert.ok(/401/i.test(err.message)); | ||
}); |
@@ -7,4 +7,4 @@ var common = require('../common'); | ||
var err = new Error('Node.js just totally exploded on me'); | ||
err.env = {protect: 'the environment!'}; | ||
err.session = {iKnow: 'what you did last minute'}; | ||
err.env = { protect: 'the environment!' }; | ||
err.session = { iKnow: 'what you did last minute' }; | ||
err.url = 'http://example.org/bad-url'; | ||
@@ -15,5 +15,6 @@ | ||
err.params = {some: 'params', circular: circular}; | ||
err.params = { some: 'params', circular: circular }; | ||
airbrake.on('vars', function(type, vars) { | ||
airbrake.on('vars', function (type, vars) { | ||
/* eslint no-param-reassign: 0 */ | ||
delete vars.SECRET; | ||
@@ -25,8 +26,8 @@ }); | ||
process.on('exit', function() { | ||
process.on('exit', function () { | ||
assert.ok(spy.called); | ||
var err = spy.args[0][0]; | ||
if (err) { | ||
throw err; | ||
var error = spy.args[0][0]; | ||
if (error) { | ||
throw error; | ||
} | ||
@@ -33,0 +34,0 @@ |
@@ -0,4 +1,5 @@ | ||
// Tests for throwing undefined, ignore rule. | ||
/* eslint no-throw-literal: 0 */ | ||
var common = require('../common'); | ||
var airbrake = require(common.dir.root).createClient(null, common.key); | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
@@ -10,3 +11,3 @@ | ||
process.on('exit', function() { | ||
process.on('exit', function () { | ||
var exitCode = (airbrake.notify.called) | ||
@@ -20,2 +21,1 @@ ? 0 | ||
throw undefined; | ||
@@ -6,9 +6,8 @@ var common = require('../common'); | ||
var assert = require('assert'); | ||
var execSync = require('sync-exec'); | ||
var spy = sinon.spy(); | ||
airbrake.trackDeployment({ | ||
rev: '98103a8fa850d5eaf3666e419d8a0a93e535b1b2', | ||
}, spy); | ||
airbrake.trackDeployment({}, spy); | ||
process.on('exit', function() { | ||
process.on('exit', function () { | ||
assert.strictEqual(spy.args[0][0], null); | ||
@@ -20,6 +19,18 @@ assert.deepEqual(Object.keys(spy.args[0][1]), [ | ||
'rev', | ||
'repo', | ||
'repo' | ||
]); | ||
assert.equal(spy.args[0][1].repo, 'git@github.com:airbrake/node-airbrake.git'); | ||
assert.equal(spy.args[0][1].rev, '98103a8fa850d5eaf3666e419d8a0a93e535b1b2'); | ||
var expectedRepo = execSync('git config --get remote.origin.url') | ||
.stdout | ||
.toString() | ||
.slice(0, -1); | ||
var expectedRev = execSync('git rev-parse HEAD') | ||
.stdout | ||
.toString() | ||
.slice(0, -1); | ||
assert.equal(spy.args[0][1].repo, expectedRepo); | ||
assert.equal(spy.args[0][1].rev, expectedRev); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
205403
5
26
760
21
8
4
- Removedxmlbuilder@~0.4.2
- Removedxmlbuilder@0.4.3(transitive)