Skip to content

Commit

Permalink
Use correct error name in message and stack
Browse files Browse the repository at this point in the history
  • Loading branch information
kommander committed May 24, 2017
1 parent f4beecc commit cc11128
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions lib/core.js
Expand Up @@ -160,10 +160,12 @@ Broken.prototype._generateMessage = function _generateMessage() {
// TODO: Move to extensions
const info = this._infoStr;

let build = [subject, ' could not ', verb, ' ', object_];
let build = [this.name, ': ', subject, ' could not ', verb, ' ', object_];
if (reason) {
if (reason instanceof Broken) {
build = build.concat(', because ', reason.message);
build = build.concat(
', because ', reason.message.replace(`${reason.name}: `, '')
);
} else {
// TODO: Move to reason getter or setter
const text = reason.message || reason.code || reason.toString();
Expand Down Expand Up @@ -331,7 +333,7 @@ Broken.prototype.__defineGetter__('data', function dataGetter() {
* @api public
*/
Broken.prototype.toString = function toString() {
return [this.name, ': ', this.message].join('');
return this.message;
};

//
Expand Down
10 changes: 5 additions & 5 deletions test/core.spec.js
Expand Up @@ -242,7 +242,7 @@ describe('Core', () => {
const err = cannot('fly', 'away');
err.subject = 'Alice';
expect(err.subject).to.be('Alice');
expect(err.message).to.be('Alice could not fly away. (No reason)');
expect(err.message).to.be('Error: Alice could not fly away. (No reason)');
});

//
Expand Down Expand Up @@ -472,7 +472,7 @@ describe('Core', () => {
expect(err).to.have.property('_infoStr');
expect(err._infoStr).to.be.a('string');
expect(err._infoStr).to.be('additional stuff');
expect(err.message).to.be('I could not fly into the sky. (No reason) (additional stuff)');
expect(err.message).to.be('Error: I could not fly into the sky. (No reason) (additional stuff)');
});

it('allows to concat info with rest arguments');
Expand All @@ -491,7 +491,7 @@ describe('Core', () => {
expect(err._infoStr).to.be.a('string');
expect(err._infoStr).to.be('additional stuff');
// eslint-disable-next-line
expect(err.message).to.be('I could not fly into the sky, because I could not overcome gravity. (No reason) (additional stuff)');
expect(err.message).to.be('Error: I could not fly into the sky, because I could not overcome gravity. (No reason) (additional stuff)');
});

//
Expand All @@ -503,7 +503,7 @@ describe('Core', () => {
expect(err._infoStr).to.be.a('string');
expect(err._infoStr).to.be('additional stuff');
// eslint-disable-next-line
expect(err.message).to.be('I could not fly into the sky. (No reason) (additional stuff)');
expect(err.message).to.be('Error: I could not fly into the sky. (No reason) (additional stuff)');
});

//
Expand All @@ -516,7 +516,7 @@ describe('Core', () => {
expect(err._infoStr).to.be.a('string');
expect(err._infoStr).to.be('additional stuff');
// eslint-disable-next-line
expect(err.message).to.be('I could not fly into the sky, because I could not overcome gravity, because I need rocket fuel. (additional stuff)');
expect(err.message).to.be('Error: I could not fly into the sky, because I could not overcome gravity, because I need rocket fuel. (additional stuff)');
});
});
});

0 comments on commit cc11128

Please sign in to comment.