Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Commit 63eb59b

Browse files
committed
fix(errors): stacktraces of custom errors should include error message
1 parent 084c7a0 commit 63eb59b

File tree

8 files changed

+66
-41
lines changed

8 files changed

+66
-41
lines changed

lib/errors/cancelled-error.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
module.exports = class CancelledError extends Error {
44
constructor() {
5-
super();
6-
5+
super('Browser request was cancelled');
76
this.name = 'CancelledError';
8-
this.message = 'Browser request was cancelled';
9-
Error.captureStackTrace(this, CancelledError);
107
}
118
};

lib/errors/gemini-error.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
'use strict';
2-
/**
3-
* Special type of error that intended to be reported
4-
* to user. Will not print stack trace by default.
5-
*/
6-
function GeminiError(message, advice) {
7-
Error.captureStackTrace(this, GeminiError);
8-
this.name = 'GeminiError';
9-
this.message = message;
10-
this.advice = advice;
11-
}
122

13-
GeminiError.prototype = Object.create(Error.prototype);
14-
GeminiError.prototype.constructor = GeminiError;
3+
module.exports = class GeminiError extends Error {
4+
constructor(message, advice) {
5+
super(message);
156

16-
module.exports = GeminiError;
7+
this.name = 'GeminiError';
8+
this.advice = advice;
9+
}
10+
};

lib/errors/no-ref-image-error.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
'use strict';
22

3-
var inherit = require('inherit'),
4-
StateError = require('./state-error');
3+
const StateError = require('./state-error');
54

6-
var NoRefImageError = inherit(StateError, {
7-
/**
8-
* @constructor
9-
* @param {String} refImagePath
10-
* @param {StateResult} result
11-
*/
12-
__constructor: function(refImagePath, currentPath) {
13-
this.name = 'NoRefImageError';
14-
this.message = 'Can not find reference image at ' + refImagePath + '.\n' +
15-
'Run `gemini update` command to capture all reference images.';
5+
module.exports = class NoRefImageError extends StateError {
6+
constructor(refImagePath, currentPath) {
7+
super(`Can not find reference image at ${refImagePath}.\n` +
8+
'Run `gemini update` command to capture all reference images.');
169

10+
this.name = 'NoRefImageError';
1711
this.currentPath = currentPath;
1812
this.refImagePath = refImagePath;
1913
}
20-
});
21-
22-
module.exports = NoRefImageError;
14+
};

lib/errors/state-error.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
* Non-fatal error, occurred during state run.
55
* Fails only single state, not the whole app.
66
*/
7-
function StateError(message, originalError) {
8-
Error.captureStackTrace(this, StateError);
9-
this.name = 'StateError';
10-
this.message = message;
11-
this.originalError = originalError;
12-
}
137

14-
StateError.prototype = Object.create(Error.prototype);
15-
StateError.prototype.constructor = StateError;
8+
module.exports = class StateError extends Error {
9+
constructor(message, originalError) {
10+
super(message);
1611

17-
module.exports = StateError;
12+
this.name = 'StateError';
13+
this.originalError = originalError;
14+
}
15+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
const CancelledError = require('lib/errors/cancelled-error');
4+
5+
describe('CancelledError', function() {
6+
it('should include the error message in the stacktrace', function() {
7+
const error = new CancelledError();
8+
9+
assert.match(error.stack, /^CancelledError: Browser request was cancelled\n/);
10+
});
11+
});

test/unit/errors/gemini-error.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
const GeminiError = require('lib/errors/gemini-error');
4+
5+
describe('GeminiError', function() {
6+
it('should include the given error message in the stacktrace', function() {
7+
const error = new GeminiError('MyCustomErrorMessage');
8+
9+
assert.match(error.stack, /^GeminiError: MyCustomErrorMessage\n/);
10+
});
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
const NoRefImageError = require('lib/errors/no-ref-image-error');
4+
5+
describe('NoRefImageError', function() {
6+
it('should include the error message in the stacktrace', function() {
7+
const error = new NoRefImageError('anyPath');
8+
9+
assert.match(error.stack, /^NoRefImageError: Can not find reference image at anyPath.\n/);
10+
});
11+
});

test/unit/errors/state-error.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
const StateError = require('lib/errors/state-error');
4+
5+
describe('StateError', function() {
6+
it('should include the given error message in the stacktrace', function() {
7+
const error = new StateError('MyCustomErrorMessage');
8+
9+
assert.match(error.stack, /^StateError: MyCustomErrorMessage\n/);
10+
});
11+
});

0 commit comments

Comments
 (0)