# Getting weird error

**URL:** <https://discourse.nodered.org/t/getting-weird-error/44700>\
**Category:** General\
**Created:** [25 April 2021 14:42 UTC](https://discourse.nodered.org/t/getting-weird-error/44700 "2021-04-25T14:42:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hoolahoous](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hoolahoous/32/16612_2.png) [@hoolahoous](https://discourse.nodered.org/u/hoolahoous)\
**Post date:** [25 April 2021 14:42 UTC](https://discourse.nodered.org/t/getting-weird-error/44700/1 "2021-04-25T14:42:02Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/586bad51b53d8135d1490bc621e87767b2af695b.png)  
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.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 April 2021 15:00 UTC](https://discourse.nodered.org/t/getting-weird-error/44700/2 "2021-04-25T15:00:58Z")

</div>

Try puttting some [node.warn()](https://nodered.org/docs/user-guide/writing-functions#logging-events) 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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 April 2021 15:01 UTC](https://discourse.nodered.org/t/getting-weird-error/44700/3 "2021-04-25T15:01:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hoolahoous](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hoolahoous/32/16612_2.png) [@hoolahoous](https://discourse.nodered.org/u/hoolahoous)\
**Post date:** [26 April 2021 16:58 UTC](https://discourse.nodered.org/t/getting-weird-error/44700/4 "2021-04-26T16:58:49Z")

</div>

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 axios.post('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.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 April 2021 18:12 UTC](https://discourse.nodered.org/t/getting-weird-error/44700/5 "2021-04-26T18:12:47Z")

</div>

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? ...

```auto
axios.get('http://xxxxx').then(resp => {
    node.send({payload:resp.data});
});

```

---

<div class="post-metadata">

**Author:** ![hoolahoous](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hoolahoous/32/16612_2.png) [@hoolahoous](https://discourse.nodered.org/u/hoolahoous)\
**Post date:** [26 April 2021 19:16 UTC](https://discourse.nodered.org/t/getting-weird-error/44700/6 "2021-04-26T19:16:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 April 2021 19:37 UTC](https://discourse.nodered.org/t/getting-weird-error/44700/7 "2021-04-26T19:37:31Z")

</div>

> [@hoolahoous](#):
>
> Also AFAIK, async/await is just syntactic sugar over promise/then so not sure if it will make any difference

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

> [@hoolahoous](#):
>
> With function and axios I can do lot more complex logic. Using http node will make it very laborious

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 June 2021 19:38 UTC](https://discourse.nodered.org/t/getting-weird-error/44700/8 "2021-06-25T19:38:02Z")

</div>

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