Log error when non-msg-object is returned from a Function

This commit is contained in:
Nick O'Leary
2017-05-15 13:54:05 +01:00
parent d4135e80a6
commit 8a7bb1be9f
3 changed files with 65 additions and 12 deletions

View File

@@ -28,18 +28,23 @@ module.exports = function(RED) {
var msgCount = 0;
for (var m=0;m<msgs.length;m++) {
if (msgs[m]) {
if (util.isArray(msgs[m])) {
for (var n=0; n < msgs[m].length; n++) {
if (msgs[m][n] !== null && msgs[m][n] !== undefined) {
msgs[m][n]._msgid = _msgid;
if (!util.isArray(msgs[m])) {
msgs[m] = [msgs[m]];
}
for (var n=0; n < msgs[m].length; n++) {
var msg = msgs[m][n];
if (msg !== null && msg !== undefined) {
if (typeof msg === 'object' && !Buffer.isBuffer(msg) && !util.isArray(msg)) {
msg._msgid = _msgid;
msgCount++;
} else {
var type = typeof msg;
if (type === 'object') {
type = Buffer.isBuffer(msg)?'Buffer':(util.isArray(msg)?'Array':'Date');
}
node.error(RED._("function.error.non-message-returned",{ type: type }))
}
}
} else {
if (msgs[m] !== null && msgs[m] !== undefined) {
msgs[m]._msgid = _msgid;
msgCount++;
}
}
}
}

View File

@@ -169,7 +169,8 @@
"outputs": "Outputs"
},
"error": {
"inputListener":"Cannot add listener to 'input' event within Function"
"inputListener":"Cannot add listener to 'input' event within Function",
"non-message-returned":"Function tried to send a message of type __type__"
},
"tip": "See the Info tab for help writing functions."
},