Skip to content

Commit 30631f0

Browse files
committed
feat: add the details property
1 parent 2961ac8 commit 30631f0

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@ throw new SemanticReleaseError('An error happened');
2424
// With error message and error code
2525
throw new SemanticReleaseError('An error happened', 'ECODE');
2626

27+
// With error message, error code and details
28+
throw new SemanticReleaseError('An error happened', 'ECODE', 'Here is some suggestions to solve this error.');
29+
2730
// With inheritance
2831
class InheritedError extends SemanticReleaseError {
29-
constructor(message, code, newProperty) {
32+
constructor(message, code, newProperty, details) {
3033
super(message);
3134
Error.captureStackTrace(this, this.constructor);
3235
this.name = this.constructor.name;
3336
this.code = code;
37+
this.details = details;
3438
this.newProperty = 'newProperty';
3539
}
3640
}
3741

38-
throw new InheritedError('An error happened', 'ECODE');
42+
throw new InheritedError('An error happened', 'ECODE', 'Here is some suggestions to solve this error.');
3943
```

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module.exports = class SemanticReleaseError extends Error {
2-
constructor(message, code) {
2+
constructor(message, code, details) {
33
super(message);
44
Error.captureStackTrace(this, this.constructor);
55
this.name = 'SemanticReleaseError';
66
this.code = code;
7+
this.details = details;
78
this.semanticRelease = true;
89
}
910
};

test/index.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ test('Sets message and code', t => {
3232
t.true(error instanceof SemanticReleaseError);
3333
});
3434

35+
test('Sets message, code and details', t => {
36+
const code = 'ENOFOO';
37+
const message = 'bar';
38+
const details = 'baz';
39+
const error = new SemanticReleaseError(message, code, details);
40+
41+
t.is(error.code, code);
42+
t.is(error.message, message);
43+
t.is(error.details, details);
44+
t.true(error.semanticRelease);
45+
t.true(error instanceof SemanticReleaseError);
46+
});
47+
3548
test('Include the stacktrace and name', async t => {
3649
const error = await t.throws(() => throwError());
3750
t.regex(error.stack, /helpers\/throw-error/);

0 commit comments

Comments
 (0)