debug node: add auto handling of error and status msgs if set to show status

This commit is contained in:
Dave Conway-Jones 2020-05-15 23:32:27 +01:00
parent 88d4d306f3
commit 1d36ce0fdf
No known key found for this signature in database
GPG Key ID: 302A6725C594817F
3 changed files with 48 additions and 22 deletions

View File

@ -52,7 +52,7 @@
complete: {value:"false", required:true}, complete: {value:"false", required:true},
targetType: {value:undefined}, targetType: {value:undefined},
statusVal: {value:""}, statusVal: {value:""},
statusType: {value:"msg"} statusType: {value:"auto"}
}, },
label: function() { label: function() {
var suffix = ""; var suffix = "";
@ -318,9 +318,14 @@
delete RED._debug; delete RED._debug;
}, },
oneditprepare: function() { oneditprepare: function() {
var autoType = {
value: "auto",
label: RED._("node-red:debug.autostatus"),
hasValue: false
};
$("#node-input-typed-status").typedInput({ $("#node-input-typed-status").typedInput({
default: "msg", default: "auto",
types:['msg',"jsonata"], types:[autoType, "msg", "jsonata"],
typeField: $("#node-input-statusType") typeField: $("#node-input-statusType")
}); });
var that = this; var that = this;
@ -339,7 +344,7 @@
} }
if (this.statusType === undefined) { if (this.statusType === undefined) {
this.statusType = this.targetType; this.statusType = this.targetType;
$("#node-input-typed-status").typedInput('type',this.statusType || "msg"); $("#node-input-typed-status").typedInput('type',this.statusType || "auto");
} }
if (typeof this.console === "string") { if (typeof this.console === "string") {
this.console = (this.console == 'true'); this.console = (this.console == 'true');
@ -385,7 +390,7 @@
if (type !== 'full') { if (type !== 'full') {
comp = $("#node-input-typed-complete").typedInput('value'); comp = $("#node-input-typed-complete").typedInput('value');
} }
that.statusType = (type !== "jsonata") ? "msg" : "jsonata"; that.statusType = "auto";
that.statusVal = comp; that.statusVal = comp;
} }
$("#node-input-typed-status").typedInput('type',that.statusType); $("#node-input-typed-status").typedInput('type',that.statusType);
@ -394,7 +399,7 @@
} }
else { else {
$("#node-tostatus-line").hide(); $("#node-tostatus-line").hide();
that.statusType = "msg"; that.statusType = "auto";
that.statusVal = ""; that.statusVal = "";
$("#node-input-typed-status").typedInput('type',that.statusType); $("#node-input-typed-status").typedInput('type',that.statusType);
$("#node-input-typed-status").typedInput('value',that.statusVal); $("#node-input-typed-status").typedInput('value',that.statusVal);

View File

@ -69,18 +69,32 @@ module.exports = function(RED) {
} }
function prepareStatus(msg, done) { function prepareStatus(msg, done) {
// Either apply the jsonata expression or... if (node.statusType === "auto") {
if (preparedStatExpression) { if (node.complete === "true") {
RED.util.evaluateJSONataExpression(preparedStatExpression, msg, (err, value) => { done(null,{msg:msg.payload});
if (err) { done(RED._("debug.invalid-exp", {error:editExpression})); } }
else { done(null,{msg:value}); } else {
}); prepareValue(msg,function(err,debugMsg) {
} else { if (err) { node.error(err); return; }
// Extract the required message property done(null,{msg:debugMsg.msg});
var output; });
try { output = RED.util.getMessageProperty(msg,node.statusVal); } }
catch(err) { output = undefined; } }
done(null,{msg:output}); else {
// Either apply the jsonata expression or...
if (preparedStatExpression) {
RED.util.evaluateJSONataExpression(preparedStatExpression, msg, (err, value) => {
if (err) { done(RED._("debug.invalid-exp", {error:editExpression})); }
else { done(null,{msg:value}); }
});
}
else {
// Extract the required message property
var output;
try { output = RED.util.getMessageProperty(msg,node.statusVal); }
catch(err) { output = undefined; }
done(null,{msg:output});
}
} }
} }
@ -93,10 +107,16 @@ module.exports = function(RED) {
if (st.length > 32) { st = st.substr(0,32) + "..."; } if (st.length > 32) { st = st.substr(0,32) + "..."; }
var fill = "grey"; var fill = "grey";
var shape = "dot"; var shape = "dot";
if (node.statusVal === "error.message" && msg.hasOwnProperty("error")) { fill = "red"; } if (node.statusType === "auto") {
if (node.statusVal === "status.text" && msg.hasOwnProperty("status")) { if (msg.hasOwnProperty("error")) {
if (msg.status.hasOwnProperty("fill")) { fill = msg.status.fill; } fill = "red";
if (msg.status.hasOwnProperty("shape")) { shape = msg.status.shape; } st = msg.error.message;
}
if (msg.hasOwnProperty("status")) {
if (msg.status.hasOwnProperty("fill")) { fill = msg.status.fill; }
if (msg.status.hasOwnProperty("shape")) { shape = msg.status.shape; }
if (msg.status.hasOwnProperty("text")) { st = msg.status.text; }
}
} }
node.status({fill:fill, shape:shape, text:st}); node.status({fill:fill, shape:shape, text:st});
}); });

View File

@ -123,6 +123,7 @@
"invalid-exp": "Invalid JSONata expression: __error__", "invalid-exp": "Invalid JSONata expression: __error__",
"msgprop": "message property", "msgprop": "message property",
"msgobj": "complete msg object", "msgobj": "complete msg object",
"autostatus": "automatic",
"to": "To", "to": "To",
"debtab": "debug tab", "debtab": "debug tab",
"tabcon": "debug tab and console", "tabcon": "debug tab and console",