Skip to content

Commit

Permalink
Review markups
Browse files Browse the repository at this point in the history
  • Loading branch information
Alec Gibson committed Nov 20, 2019
1 parent 751728c commit c0e9e0b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
13 changes: 5 additions & 8 deletions lib/error.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
function ShareDBError(code, message) {
this.name = 'ShareDBError';
this.code = code || ShareDBError.CODES.ERR_UNKNOWN_ERROR;
this.message = message;
if (this.canCaptureStackTrace()) {
this.code = code;
this.message = message || '';
if (Error.captureStackTrace) {
Error.captureStackTrace(this, ShareDBError);
} else {
this.stack = new Error().stack;
}
}

ShareDBError.prototype = Object.create(Error.prototype);

ShareDBError.prototype.canCaptureStackTrace = function() {
return !!Error.captureStackTrace;
};
ShareDBError.prototype.constructor = ShareDBError;
ShareDBError.prototype.name = 'ShareDBError';

ShareDBError.CODES = {
ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT: 'ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT',
Expand Down
18 changes: 0 additions & 18 deletions test/error.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
var ShareDBError = require('../lib/error');
var expect = require('chai').expect;
var sinon = require('sinon');

describe('ShareDBError', function() {
afterEach(function() {
sinon.restore();
});

it('can be identified by instanceof', function() {
var error = new ShareDBError();
expect(error).to.be.instanceof(ShareDBError);
Expand All @@ -33,17 +28,4 @@ describe('ShareDBError', function() {
expect(error.stack).to.contain('badFunction');
}
});

it('has a stack trace when Error.captureStackTrace is not implemented', function() {
sinon.stub(ShareDBError.prototype, 'canCaptureStackTrace').returns(false);
function badFunction() {
throw new ShareDBError();
}

try {
badFunction();
} catch (error) {
expect(error.stack).to.contain('badFunction');
}
});
});

0 comments on commit c0e9e0b

Please sign in to comment.