Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions packages/error-reporting/src/interfaces/manual.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ function handlerSetup(client, config) {
}

if (err instanceof ErrorMessage) {
var fauxError = new Error(err.message);

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

var fullStack = fauxError.stack.split('\n');
var cleanedStack = fullStack.slice(0, 1).concat(fullStack.slice(2)).join('\n');

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

err.setMessage(cleanedStack);
em = err;
} else {
em = new ErrorMessage();
Expand Down
50 changes: 36 additions & 14 deletions packages/error-reporting/system-test/testAuthClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,9 @@ describe('Expected Behavior', function() {
});

describe('error-reporting', function() {
const TIMESTAMP = Date.now();
const BASE_NAME = 'error-reporting-system-test';
function buildName(suffix) {
return [TIMESTAMP, BASE_NAME, suffix].join('_');
return [Date.now(), BASE_NAME, suffix].join('_');
}

const SERVICE_NAME = buildName('service-name');
Expand All @@ -390,15 +389,8 @@ describe('error-reporting', function() {
});
});

it('Should correctly publish errors', function(done) {
// After an error is reported, this test waits TIMEOUT ms before
// verifying the error has been reported to ensure the system had
// enough time to receive the error report and process it.
// As such, this test is set to fail due to a timeout only if sufficiently
// more than TIMEOUT ms has elapsed to avoid test fragility.
this.timeout(TIMEOUT * 2);
var errorId = buildName('message');
errors.report(new Error(errorId), function(err, response, body) {
function verifyReporting(errOb, expectedMessage, timeout, cb) {
errors.report(errOb, function(err, response, body) {
assert.ifError(err);
assert(isObject(response));
assert.deepEqual(body, {});
Expand All @@ -410,7 +402,7 @@ describe('error-reporting', function() {

var matchedErrors = groups.filter(function(errItem) {
return errItem && errItem.representative &&
errItem.representative.message.startsWith('Error: ' + errorId);
errItem.representative.message.startsWith(expectedMessage);
});

// The error should have been reported exactly once
Expand All @@ -424,9 +416,39 @@ describe('error-reporting', function() {
assert.ok(context);
assert.strictEqual(context.service, SERVICE_NAME);
assert.strictEqual(context.version, SERVICE_VERSION);
done();
cb();
});
}, TIMEOUT);
}, timeout);
});
}

// For each test below, after an error is reported, the test waits
// TIMEOUT ms before verifying the error has been reported to ensure
// the system had enough time to receive the error report and process it.
// As such, each test is set to fail due to a timeout only if sufficiently
// more than TIMEOUT ms has elapsed to avoid test fragility.

it('Should correctly publish errors using the Error constructor',
function(done) {
this.timeout(TIMEOUT * 2);
var errorId = buildName('with-error-constructor');
var errOb = new Error(errorId);
var expectedMessage = 'Error: ' + errorId;
verifyReporting(errOb, expectedMessage, TIMEOUT, done);
});

it('Should correctly publish errors using a string', function(done) {
this.timeout(TIMEOUT * 2);
var errorId = buildName('with-string');
verifyReporting(errorId, errorId, TIMEOUT, done);
});

it('Should correctly publish errors using an error builder', function(done) {
this.timeout(TIMEOUT * 2);
var errorId = buildName('with-error-builder');
var expectedMessage = 'Error: ' + errorId;
var errOb = errors.event()
.setMessage(errorId);
verifyReporting(errOb, expectedMessage, TIMEOUT, done);
});
});
4 changes: 2 additions & 2 deletions packages/error-reporting/test/unit/interfaces/manual.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('Manual handler', function() {
it('Should accept builder inst as only argument', function() {
var msg = 'test';
var r = report(new ErrorMessage().setMessage(msg));
assert.strictEqual(r.message, msg,
assert(r.message.startsWith('Error: ' + msg),
'string message should propagate from error message inst');
});
it('Should accept builder and request as arguments', function() {
Expand All @@ -153,7 +153,7 @@ describe('Manual handler', function() {
new ErrorMessage().setMessage(msg).consumeRequestInformation(oldReq),
newReq
);
assert.strictEqual(r.message, msg,
assert(r.message.startsWith('Error: ' + msg),
'string message should propagate from error message inst');
assert.strictEqual(r.context.httpRequest.method, newReq.method,
[
Expand Down