Skip to content

Commit 61045dd

Browse files
Dave Conway-JonesDave Conway-Jones
authored andcommitted
try to fix debug node non-standard object type handling.
1 parent 1bf72a0 commit 61045dd

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

nodes/core/core/58-debug.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,22 @@ module.exports = function(RED) {
8686
msg.msg = msg.msg.toString('hex');
8787
} else if (typeof msg.msg === 'object') {
8888
var seen = [];
89-
msg.format = "object";
89+
msg.format = msg.msg.constructor.name || "Object";
9090
var isArray = util.isArray(msg.msg);
91-
if (!isArray && msg.msg.toString !== Object.prototype.toString) {
92-
msg.format = msg.msg.constructor.name || "object";
93-
msg.msg = msg.msg.toString();
94-
} else {
95-
if (isArray) {
96-
msg.format = "array ["+msg.msg.length+"]";
97-
}
91+
if (isArray) {
92+
msg.format = "array ["+msg.msg.length+"]";
93+
}
94+
if (isArray || (msg.format === "Object")) {
9895
msg.msg = JSON.stringify(msg.msg, function(key, value) {
9996
if (typeof value === 'object' && value !== null) {
10097
if (seen.indexOf(value) !== -1) { return "[circular]"; }
10198
seen.push(value);
10299
}
103100
return value;
104101
}," ");
102+
} else {
103+
try { msg.msg = msg.msg.toString(); }
104+
catch(e) { msg.msg = "[Type not printable]"; }
105105
}
106106
seen = null;
107107
} else if (typeof msg.msg === "boolean") {

test/nodes/core/core/58-debug_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('debug node', function() {
9494
}, function(msg) {
9595
JSON.parse(msg).should.eql({
9696
topic:"debug",
97-
data:{id:"n1",msg:'{\n "payload": "test"\n}',format:"object"}
97+
data:{id:"n1",msg:'{\n "payload": "test"\n}',format:"Object"}
9898
});
9999
}, done);
100100
});
@@ -179,7 +179,7 @@ describe('debug node', function() {
179179
}, function(msg) {
180180
JSON.parse(msg).should.eql({
181181
topic:"debug",
182-
data:{id:"n1",msg:'{\n "type": "foo"\n}',property:"payload",format:"object"}
182+
data:{id:"n1",msg:'{\n "type": "foo"\n}',property:"payload",format:"Object"}
183183
});
184184
}, done);
185185
});
@@ -215,7 +215,7 @@ describe('debug node', function() {
215215
data:{
216216
id:"n1",
217217
msg:'{\n "name": "bar",\n "o": "[circular]"\n}',
218-
property:"payload",format:"object"
218+
property:"payload",format:"Object"
219219
}
220220
});
221221
}, done);

0 commit comments

Comments
 (0)