From 30631f0fc13d7ee6dc9e63cd119ce5d87db0cbd4 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Sun, 4 Feb 2018 04:05:57 -0500 Subject: [PATCH] feat: add the `details` property --- README.md | 8 ++++++-- index.js | 3 ++- test/index.test.js | 13 +++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 18895fe..9ebecdf 100644 --- a/README.md +++ b/README.md @@ -24,16 +24,20 @@ throw new SemanticReleaseError('An error happened'); // With error message and error code throw new SemanticReleaseError('An error happened', 'ECODE'); +// With error message, error code and details +throw new SemanticReleaseError('An error happened', 'ECODE', 'Here is some suggestions to solve this error.'); + // With inheritance class InheritedError extends SemanticReleaseError { - constructor(message, code, newProperty) { + constructor(message, code, newProperty, details) { super(message); Error.captureStackTrace(this, this.constructor); this.name = this.constructor.name; this.code = code; + this.details = details; this.newProperty = 'newProperty'; } } -throw new InheritedError('An error happened', 'ECODE'); +throw new InheritedError('An error happened', 'ECODE', 'Here is some suggestions to solve this error.'); ``` diff --git a/index.js b/index.js index 8df7887..68800c2 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,10 @@ module.exports = class SemanticReleaseError extends Error { - constructor(message, code) { + constructor(message, code, details) { super(message); Error.captureStackTrace(this, this.constructor); this.name = 'SemanticReleaseError'; this.code = code; + this.details = details; this.semanticRelease = true; } }; diff --git a/test/index.test.js b/test/index.test.js index d74a398..ffc6209 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -32,6 +32,19 @@ test('Sets message and code', t => { t.true(error instanceof SemanticReleaseError); }); +test('Sets message, code and details', t => { + const code = 'ENOFOO'; + const message = 'bar'; + const details = 'baz'; + const error = new SemanticReleaseError(message, code, details); + + t.is(error.code, code); + t.is(error.message, message); + t.is(error.details, details); + t.true(error.semanticRelease); + t.true(error instanceof SemanticReleaseError); +}); + test('Include the stacktrace and name', async t => { const error = await t.throws(() => throwError()); t.regex(error.stack, /helpers\/throw-error/);