Skip to content

Commit 6b978eb

Browse files
pvdlggr2m
authored andcommitted
fix: Include stacktrace and name in SemanticReleaseError
1 parent 97137c4 commit 6b978eb

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
module.exports = SemanticReleaseError;
2-
3-
SemanticReleaseError.prototype = new Error();
4-
5-
function SemanticReleaseError(message, code) {
6-
Error.captureStackTrace(this, this.constructor);
7-
this.name = this.constructor.name;
8-
this.message = message;
9-
this.code = code;
10-
}
1+
module.exports = class SemanticReleaseError extends Error {
2+
constructor(message, code) {
3+
super(message);
4+
Error.captureStackTrace(this, this.constructor);
5+
this.name = this.constructor.name;
6+
this.code = code;
7+
}
8+
};

test/helpers/throw-error.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import SemanticReleaseError from '../../index';
2+
3+
export default () => {
4+
throw new SemanticReleaseError('message', 'code');
5+
};

test/index.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test from 'ava';
22
import SemanticReleaseError from '../index';
3+
import throwError from './helpers/throw-error';
34

45
test('Instanciates error', t => {
56
const error = new SemanticReleaseError();
@@ -14,11 +15,17 @@ test('Sets message', t => {
1415
t.is(error.message, message);
1516
});
1617

17-
test('Sets message and code', function(t) {
18+
test('Sets message and code', t => {
1819
const code = 'ENOFOO';
1920
const message = 'bar';
2021
const error = new SemanticReleaseError(message, code);
2122

2223
t.is(error.code, code);
2324
t.is(error.message, message);
2425
});
26+
27+
test('Include the stacktrace and name', async t => {
28+
const error = await t.throws(() => throwError());
29+
t.regex(error.stack, /helpers\/throw-error/);
30+
t.is(error.name, 'SemanticReleaseError');
31+
});

0 commit comments

Comments
 (0)