Catch JSON stringily errors.

There is a chance that there may be circular references in the Object which will cause the debug message to throw an exception. If the exception is not handled on the application level this will cause node to crash. As a debug library, errors in here should not have such a serious impact on the application.
This commit is contained in:
Jovan Alleyne 2015-04-08 15:25:48 -04:00
parent 105497d62c
commit 6830d9fbee
2 changed files with 10 additions and 2 deletions

View File

@ -59,7 +59,11 @@ function useColors() {
*/
exports.formatters.j = function(v) {
return JSON.stringify(v);
try {
return JSON.stringify(v);
}catch( err){
return '[UnexpectedJSONParseError]: ' + err.message;
}
};

6
dist/debug.js vendored
View File

@ -384,7 +384,11 @@ function useColors() {
*/
exports.formatters.j = function(v) {
return JSON.stringify(v);
try {
return JSON.stringify(v);
}catch( err){
return '[UnexpectedJSONParseError]: ' + err.message;
}
};