Skip to content

Commit 044af51

Browse files
committed
Added handling for undefined errors and test coverage
Fixes #1827
1 parent bad2a30 commit 044af51

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

core/server/errorHandling.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ errors = {
5656

5757
logError: function (err, context, help) {
5858
var stack = err ? err.stack : null;
59-
err = err.message || err || 'Unknown';
59+
if (err) {
60+
err = err.message || err || 'An unknown error occurred.';
61+
} else {
62+
err = 'An unknown error occurred.';
63+
}
6064
// TODO: Logging framework hookup
6165
// Eventually we'll have better logging which will know about envs
6266
if ((process.env.NODE_ENV === 'development' ||

core/test/unit/errorHandling_spec.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,86 @@ describe("Error handling", function () {
115115
logStub.lastCall.calledWith('').should.be.true;
116116
});
117117

118+
it("logs errors from an undefined error argument", function () {
119+
var message = "Testing";
120+
121+
errors.logError(undefined, message, message);
122+
123+
// Calls log with message on Error objects
124+
125+
logStub.callCount.should.equal(4);
126+
logStub.firstCall.calledWith("\nERROR:".red, "An unknown error occurred.".red).should.be.true;
127+
logStub.secondCall.calledWith(message.white).should.be.true;
128+
logStub.thirdCall.calledWith(message.green).should.be.true;
129+
logStub.lastCall.calledWith('').should.be.true;
130+
});
131+
132+
it("logs errors from an undefined context argument", function () {
133+
var message = "Testing";
134+
135+
errors.logError(message, undefined, message);
136+
137+
// Calls log with message on Error objects
138+
139+
logStub.callCount.should.equal(3);
140+
logStub.firstCall.calledWith("\nERROR:".red, message.red).should.be.true;
141+
logStub.secondCall.calledWith(message.green).should.be.true;
142+
logStub.lastCall.calledWith('').should.be.true;
143+
});
144+
145+
it("logs errors from an undefined help argument", function () {
146+
var message = "Testing";
147+
148+
errors.logError(message, message, undefined);
149+
150+
// Calls log with message on Error objects
151+
152+
logStub.callCount.should.equal(3);
153+
logStub.firstCall.calledWith("\nERROR:".red, message.red).should.be.true;
154+
logStub.secondCall.calledWith(message.white).should.be.true;
155+
logStub.lastCall.calledWith('').should.be.true;
156+
});
157+
158+
it("logs errors from a null error argument", function () {
159+
var message = "Testing";
160+
161+
errors.logError(null, message, message);
162+
163+
// Calls log with message on Error objects
164+
165+
logStub.callCount.should.equal(4);
166+
logStub.firstCall.calledWith("\nERROR:".red, "An unknown error occurred.".red).should.be.true;
167+
logStub.secondCall.calledWith(message.white).should.be.true;
168+
logStub.thirdCall.calledWith(message.green).should.be.true;
169+
logStub.lastCall.calledWith('').should.be.true;
170+
});
171+
172+
it("logs errors from a null context argument", function () {
173+
var message = "Testing";
174+
175+
errors.logError(message, null, message);
176+
177+
// Calls log with message on Error objects
178+
179+
logStub.callCount.should.equal(3);
180+
logStub.firstCall.calledWith("\nERROR:".red, message.red).should.be.true;
181+
logStub.secondCall.calledWith(message.green).should.be.true;
182+
logStub.lastCall.calledWith('').should.be.true;
183+
});
184+
185+
it("logs errors from a null help argument", function () {
186+
var message = "Testing";
187+
188+
errors.logError(message, message, null);
189+
190+
// Calls log with message on Error objects
191+
192+
logStub.callCount.should.equal(3);
193+
logStub.firstCall.calledWith("\nERROR:".red, message.red).should.be.true;
194+
logStub.secondCall.calledWith(message.white).should.be.true;
195+
logStub.lastCall.calledWith('').should.be.true;
196+
});
197+
118198
it("logs promise errors and redirects", function (done) {
119199
var def = when.defer(),
120200
prom = def.promise,

0 commit comments

Comments
 (0)