From 6830d9fbeeebdf46700b6ad0426f36d009114c7e Mon Sep 17 00:00:00 2001 From: Jovan Alleyne Date: Wed, 8 Apr 2015 15:25:48 -0400 Subject: [PATCH] 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. --- browser.js | 6 +++++- dist/debug.js | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/browser.js b/browser.js index 55f4cf9..ab49587 100644 --- a/browser.js +++ b/browser.js @@ -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; + } }; diff --git a/dist/debug.js b/dist/debug.js index 97d6f78..e6732b8 100644 --- a/dist/debug.js +++ b/dist/debug.js @@ -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; + } };