Skip to content

Commit

Permalink
handle error as string, tapjs#72
Browse files Browse the repository at this point in the history
PR-URL: tapjs#74
Credit: @vitalets
Close: tapjs#74
Reviewed-by: @isaacs
  • Loading branch information
vitalets authored and isaacs committed Sep 26, 2023
1 parent a1c5381 commit d0bbe5b
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,26 @@ function getError (result) {
}

if (result.diag && result.diag.error) {
err = {
name: result.diag.error.name || 'Error',
message: result.diag.error.message,
toString: function () {
return this.name + ': ' + this.message
},
stack: result.diag.error.stack
}
// see: https://github.com/tapjs/tap-mocha-reporter/issues/72
if (typeof result.diag.error === 'string') {
err = {
name: 'Error',
message: result.diag.error,
toString: function () {
return this.name + ': ' + this.message
},
stack: result.diag.stack
}
} else {
err = {
name: result.diag.error.name || 'Error',
message: result.diag.error.message,
toString: function () {
return this.name + ': ' + this.message
},
stack: result.diag.error.stack
}
}
} else {
err = {
message: (result.name || '(unnamed error)').replace(/^Error: /, ''),
Expand Down

0 comments on commit d0bbe5b

Please sign in to comment.