File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed
Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -24,16 +24,20 @@ throw new SemanticReleaseError('An error happened');
2424// With error message and error code
2525throw 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
2831class 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```
Original file line number Diff line number Diff line change 11module . 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} ;
Original file line number Diff line number Diff 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+
3548test ( 'Include the stacktrace and name' , async t => {
3649 const error = await t . throws ( ( ) => throwError ( ) ) ;
3750 t . regex ( error . stack , / h e l p e r s \/ t h r o w - e r r o r / ) ;
You can’t perform that action at this time.
0 commit comments