Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit 186e206

Browse files
committed
Changed tests to truly go off the toString method and fixed resulting failures
1 parent f88e30a commit 186e206

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

lib/PluginError.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function PluginError(plugin, message, opt) {
6060
// safety object, then we'll get stack overflow problems.
6161
var safety = {
6262
toString: function() {
63-
return this.messageDetails + '\nStack:';
63+
return this.messageWithDetails + '\nStack:';
6464
}.bind(this)
6565
};
6666
Error.captureStackTrace(safety, arguments.callee || this.constructor);
@@ -73,17 +73,26 @@ function PluginError(plugin, message, opt) {
7373

7474
util.inherits(PluginError, Error);
7575

76+
PluginError.prototype.__defineGetter__('messageWithDetails', function() {
77+
var details = this.messageDetails;
78+
79+
if (details === '') {
80+
return 'Message:\t ' + this.message;
81+
}
82+
83+
return 'Message:\t ' + this.message + '\n' + details;
84+
});
85+
7686
PluginError.prototype.__defineGetter__('messageDetails', function() {
77-
debugger;
7887
if (this.showProperties) {
7988
var res = _(Object.keys(this))
8089
.filter(function(prop) { return propertiesNotToDisplay.indexOf(prop) === -1; })
8190
.map(function(prop) { return '\n ' + prop + ': ' + this[prop]; }, this)
8291
.reduce(function(properties, next) { return properties + next; });
8392

84-
return 'Message:\n ' + this.message + '\nDetails:' + res;
93+
return 'Details:' + res;
8594
} else {
86-
return 'Message:\n ' + this.message;
95+
return '';
8796
}
8897
});
8998

@@ -94,9 +103,9 @@ PluginError.prototype.toString = function () {
94103
if (this.__safety) {
95104
msg = this.__safety.stack;
96105
} else if (this._stack) {
97-
msg = this._stack;
106+
msg = this.messageWithDetails + '\n' + this._stack;
98107
} else {
99-
msg = this.stack;
108+
msg = this.messageWithDetails + '\n' + this.stack;
100109
}
101110
} else {
102111
msg = this.messageDetails;

test/PluginError.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@ describe('PluginError()', function(){
102102
var realErr = new Error('something broke');
103103
realErr.fileName = 'original.js';
104104
var err = new util.PluginError('test', realErr, {showStack: true});
105-
err.messageDetails.indexOf('message:').should.equal(-1);
106-
err.messageDetails.indexOf('fileName:').should.not.equal(-1);
105+
err.toString().indexOf('message:').should.equal(-1);
106+
err.toString().indexOf('fileName:').should.not.equal(-1);
107107
});
108108

109109
it('should show properties added after the error is created', function(){
110110
var realErr = new Error('something broke');
111111
var err = new util.PluginError('test', realErr);
112112
err.fileName = 'original.js';
113-
err.messageDetails.indexOf('message:').should.equal(-1);
114-
err.messageDetails.indexOf('fileName:').should.not.equal(-1);
113+
err.toString().indexOf('message:').should.equal(-1);
114+
err.toString().indexOf('fileName:').should.not.equal(-1);
115115
});
116116

117117
it('should toString quickly', function(done) {

0 commit comments

Comments
 (0)