Skip to content

Commit

Permalink
Catch JSON stringily errors.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jalleyne committed Apr 8, 2015
1 parent 105497d commit 6830d9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};


Expand Down
6 changes: 5 additions & 1 deletion dist/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};


Expand Down

0 comments on commit 6830d9f

Please sign in to comment.