In node-red how can I send a message to the debug tab with out using debug node? Is there method I could call
Asked Answered
M

2

14

Node-RED flow

I dont want use debug node. rather I want to just pass the debug message to the debug tab directly from my customized node. So I was wondering if may be there is a method that I could use to achieve this.

Mulatto answered 3/3, 2016 at 9:10 Comment(1)
Why do you not want to use a debug node?Road
R
16

The node object is exposed in the context of a function node and had 2 functions that will add something to the debug tab

node.warn() and node.error() both print to the debug tab (and also to the console) but with suitable colours and header messages e.g.

node.warn(msg.payload);
return msg;

warn and error messages in debug tab

Be aware that node.error will also raise a message that can be caught by the Catch node so if you just want to report status from with in a function then the node.warn is probably best

Road answered 3/3, 2016 at 9:29 Comment(5)
Once a node.error() is invoked, should it be followed with a return null statement to halt the flow? Or, will that happen on its own?Lewislewisite
That entirely depends on the context of where it was calledRoad
An example, please?Lewislewisite
It's bad that there is no node.debugWilley
@Willey There is a node.debug() but it is not for sending items to the sidebar. nodered.org/docs/user-guide/writing-functions#logging-eventsRoad
L
0

You can use the context store of the node.

in Start of node :

if(context.get("errors") === undefined) {
    context.set("errors", [])
}

in Function of node :

context.get('errors').push({
   status: 'err',
   message: 'There is an error',
   ts: new Date(),
   details: {
       no: '001'
   }
})

or

const pushError = (error) => {
    context.get('errors').push({
        status: 'err',
        message: 'There is an error',
        ts: new Date(),
        details: error
    })
}

try {
    ....
} catch(ex) {
    pushError(ex)
}

return msg;
Largish answered 12/12, 2023 at 7:8 Comment(1)
This doesn't answer the question, storing an error in the context does not add it to the debug sidebarRoad

© 2022 - 2024 — McMap. All rights reserved.