Skip to content

Commit 6830d9f

Browse files
committed
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.
1 parent 105497d commit 6830d9f

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

browser.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ function useColors() {
5959
*/
6060

6161
exports.formatters.j = function(v) {
62-
return JSON.stringify(v);
62+
try {
63+
return JSON.stringify(v);
64+
}catch( err){
65+
return '[UnexpectedJSONParseError]: ' + err.message;
66+
}
6367
};
6468

6569

dist/debug.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,11 @@ function useColors() {
384384
*/
385385

386386
exports.formatters.j = function(v) {
387-
return JSON.stringify(v);
387+
try {
388+
return JSON.stringify(v);
389+
}catch( err){
390+
return '[UnexpectedJSONParseError]: ' + err.message;
391+
}
388392
};
389393

390394

0 commit comments

Comments
 (0)