Getting weird error

I have a flow where I do some HTTP post using axios library (in function node). I attached a debug node to output. Function node makes http call, and sets the result object as payload and sends it forward to debug node. That debug node is set to display full msg object.

However, randomly I see following error on node-red side debug pane. This error points to "debug" node (not function node). Instead of debug node title "msg : Object" it is "msg: error" and then it shows following error

"TypeError: encodeObject Error: [Cannot read property 'reading' of null] Value: {...."

remaining part is followed by json representation of full message object.
This doesn't seem to originate from my function node because

  1. The debug message points to debug node and not function node (it carries name of debug node, and when I hover over name , debug node gets highlighted in center pane and not function node)
  2. I do not have any property called "reading" in my function node.

Any ideas what could be wrong ? Is there some kind of race condition (unresolved promise?) in debug node which is not able to handle some thing in incoming payload ? Mind you that result payload generated in function node is generated using 'await axios..' so any network IO related to axios would have already resolved.

Try puttting some node.warn() statements in your function node to display what is being used to build the msg being sent out.
example: node.warn("xxx="+xxx); if xxx = '34, you should see xxx=34 in the debug sidebar.

Also, could you post your function and a screenshot of the debug please?

What hardware/OS are you running on and what version of node red and nodejs?
The node red version is at the bottom of the menu dropdown and the nodejs version by
node -v
in a terminal

I am still working on creating a reproducer (since it happens intermittently) and not all the time. Here are few additional observations

  1. This happens when I attach a response object from axios call (in function object) to msg object and pass it to debug node. e.g. in function node -

msg.result = await'someURL',locations, {"headers": headers});
return msg;

  1. doesn't happen if parse the results in function object and attach any other text or static values to message object.

I tried switching 'axios' with 'got' but still got error randomly. So something in the response object caused the issue.

Just a question. Why are you using axios & got in a function instead of using the http request node?

Have you tried using .then() & node.send instead of async await? ...

axios.get('http://xxxxx').then(resp => {

With function and axios I can do lot more complex logic. Using http node will make it very laborious (will have to use function node anyways to process cookies and data before next call)
Also AFAIK, async/await is just syntactic sugar over promise/then so not sure if it will make any difference. I am leaning towards hunch that some of promises within response object may have not resolved fully or there might be a stream/socket which is not fully closed by the time it gets to debug node

Yes, but did you try the .then & node.send over await & return msg?

Maybe so but you can be clever with it, using subflows or a subroutine-like node you can reuse and hide complexities.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.