Skip to content

Commit

Permalink
remove uncaught interface (#2208)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiancavalli authored and stephenplusplus committed Apr 14, 2017
1 parent cc9604a commit 326ad28
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 315 deletions.
14 changes: 14 additions & 0 deletions packages/error-reporting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ var errors = require('@google-cloud/error-reporting')({
errors.report(new Error('Something broke!'));
```

- **One may even catch and report application-wide uncaught errors:**
- *It is recommended to catch uncaughtExceptions for production-deployed applications*
- To read more about uncaught exception handling in Node.js and what it means for your application [please click here](https://nodejs.org/api/process.html#process_event_uncaughtexception)

```js
var errors = require('@google-cloud/error-reporting')();
process.on('uncaughtException', (e) => {
// Write the error to stderr.
console.error(e);
// Report that same error the Stackdriver Error Service
errors.report(e);
});
```

1. **View reported errors:**

Open Stackdriver Error Reporting at https://console.cloud.google.com/errors to view the reported errors.
Expand Down
29 changes: 0 additions & 29 deletions packages/error-reporting/src/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,6 @@ var Configuration = function(givenConfig, logger) {
* @defaultvalue Object
*/
this._logger = logger;
/**
* The _reportUncaughtExceptions property is meant to contain the optional
* runtime configuration property reportUncaughtExceptions. This property will
* default to true if not given false through the runtime configuration
* meaning that the default behavior is to catch uncaught exceptions, report
* them to the Stackdriver Errors API and then exit. If given false uncaught
* exceptions will not be listened for and not be caught or reported.
* @memberof Configuration
* @private
* @type {Boolean}
* @defaultvalue true
*/
this._reportUncaughtExceptions = true;
/**
* The _shouldReportErrorsToAPI property is meant to denote whether or not
* the Stackdriver error reporting library will actually try to report Errors
Expand Down Expand Up @@ -276,12 +263,6 @@ Configuration.prototype._gatherLocalConfiguration = function() {
'true in the runtime configuration object'
].join(' '));
}
if (isBoolean(this._givenConfiguration.reportUncaughtExceptions)) {
this._reportUncaughtExceptions = this._givenConfiguration
.reportUncaughtExceptions;
} else if (has(this._givenConfiguration, 'reportUncaughtExceptions')) {
throw new Error('config.reportUncaughtExceptions must be a boolean');
}
if (isString(this._givenConfiguration.key)) {
this._key = this._givenConfiguration.key;
} else if (has(this._givenConfiguration, 'key')) {
Expand Down Expand Up @@ -357,16 +338,6 @@ Configuration.prototype._checkLocalProjectId = function(cb) {
}
return this._projectId;
};
/**
* Returns the _reportUncaughtExceptions property on the instance.
* @memberof Configuration
* @public
* @function getReportUncaughtExceptions
* @returns {Boolean} - returns the _reportUncaughtExceptions property
*/
Configuration.prototype.getReportUncaughtExceptions = function() {
return this._reportUncaughtExceptions;
};
/**
* Returns the _shouldReportErrorsToAPI property on the instance.
* @memberof Configuration
Expand Down
4 changes: 0 additions & 4 deletions packages/error-reporting/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var manual = require('./interfaces/manual.js');
var express = require('./interfaces/express.js');
var restify = require('./interfaces/restify');
var messageBuilder = require('./interfaces/message-builder.js');
var uncaughtException = require('./interfaces/uncaught.js');
var createLogger = require('./logger.js');

/**
Expand Down Expand Up @@ -84,9 +83,6 @@ function Errors(initConfiguration) {
var config = new Configuration(initConfiguration, logger);
var client = new AuthClient(config, logger);

// Setup the uncaught exception handler
uncaughtException(client, config);

// Build the application interfaces for use by the hosting application
/**
* @example
Expand Down
67 changes: 0 additions & 67 deletions packages/error-reporting/src/interfaces/uncaught.js

This file was deleted.

93 changes: 0 additions & 93 deletions packages/error-reporting/test/fixtures/uncaughtExitBehaviour.js

This file was deleted.

27 changes: 0 additions & 27 deletions packages/error-reporting/test/unit/testConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var nock = require('nock');

var METADATA_URL = 'http://metadata.google.internal/computeMetadata/v1/project';

process.removeAllListeners('uncaughtException');
var env = {
NODE_ENV: process.env.NODE_ENV,
GCLOUD_PROJECT: process.env.GCLOUD_PROJECT,
Expand Down Expand Up @@ -84,12 +83,6 @@ describe('Configuration class', function() {
it('Should have a property reflecting the config argument', function() {
assert.deepEqual(c._givenConfiguration, stubConfig);
});
it('Should reportUncaughtExceptions', function() {
assert.strictEqual(c.getReportUncaughtExceptions(), true);
});
it('Should not reportUncaughtExceptions', function() {
assert.strictEqual(c.getShouldReportErrorsToAPI(), false);
});
it('Should not have a project id', function() {
assert.strictEqual(c._projectId, null);
});
Expand Down Expand Up @@ -125,11 +118,6 @@ describe('Configuration class', function() {
});
});
describe('exception behaviour', function() {
it('Should throw', function() {
assert.throws(function() {
new Configuration({reportUncaughtExceptions: 1}, logger);
});
});
it('Should throw if invalid type for key', function() {
assert.throws(function() {
new Configuration({key: null}, logger);
Expand Down Expand Up @@ -294,21 +282,6 @@ describe('Configuration class', function() {
assert.strictEqual(c.getKey(), key);
});
});
describe('reportUncaughtExceptions', function() {
var c;
var projectId = '123-xyz';
var reportUncaughtExceptions = false;
before(function() {
c = new Configuration({
projectId: projectId,
reportUncaughtExceptions: reportUncaughtExceptions
});
});
it('Should assign', function() {
assert.strictEqual(c.getReportUncaughtExceptions(),
reportUncaughtExceptions);
});
});
});
});
});
Loading

0 comments on commit 326ad28

Please sign in to comment.