mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Use json-stringify-safe to detect circular references in debug msgs
This commit is contained in:
parent
bba3ca8cc0
commit
e7cc42a927
@ -19,6 +19,7 @@ module.exports = function(RED) {
|
||||
var util = require("util");
|
||||
var events = require("events");
|
||||
var path = require("path");
|
||||
var safeJSONStringify = require("json-stringify-safe");
|
||||
var debuglength = RED.settings.debugMaxLength||1000;
|
||||
var useColors = false;
|
||||
// util.inspect.styles.boolean = "red";
|
||||
@ -87,6 +88,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
} else if (msg.msg && typeof msg.msg === 'object') {
|
||||
var seen = [];
|
||||
var seenAts = [];
|
||||
try {
|
||||
msg.format = msg.msg.constructor.name || "Object";
|
||||
} catch(err) {
|
||||
@ -106,7 +108,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
}
|
||||
if (isArray || (msg.format === "Object")) {
|
||||
msg.msg = JSON.stringify(msg.msg, function(key, value) {
|
||||
msg.msg = safeJSONStringify(msg.msg, function(key, value) {
|
||||
if (key[0] === '_' && key !== "_msgid") {
|
||||
return undefined;
|
||||
}
|
||||
@ -124,10 +126,6 @@ module.exports = function(RED) {
|
||||
length: value.length
|
||||
}
|
||||
}
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
if (seen.indexOf(value) !== -1) { return "[circular]"; }
|
||||
seen.push(value);
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
if (value.length > debuglength) {
|
||||
return value.substring(0,debuglength)+"...";
|
||||
|
@ -41,6 +41,7 @@
|
||||
"i18next":"1.10.6",
|
||||
"is-utf8":"0.2.1",
|
||||
"js-yaml": "3.6.1",
|
||||
"json-stringify-safe":"5.0.1",
|
||||
"jsonata":"1.0.10",
|
||||
"media-typer": "0.3.0",
|
||||
"mqtt": "1.14.1",
|
||||
|
Loading…
Reference in New Issue
Block a user