# Odd problem with function node in v1.1.3. Bug?

**URL:** https://discourse.nodered.org/t/odd-problem-with-function-node-in-v1-1-3-bug/33636
**Category:** General
**Created:** [1 October 2020 16:51 UTC](https://discourse.nodered.org/t/odd-problem-with-function-node-in-v1-1-3-bug/33636 "2020-10-01T16:51:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [1 October 2020 16:51 UTC](https://discourse.nodered.org/t/odd-problem-with-function-node-in-v1-1-3-bug/33636/1 "2020-10-01T16:51:47Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/de7d9a471eb7c6aff5eb6eb175df7b7a78b00a43.png)

The node thinks there is an error in the function code. As it happens, there _is_ an error as you can see from the raw data in the debug output.

But I don't know how the node could know that since it has no access to the incoming example msg. As far as the editor is concerned, `msg.payload[package]` certainly _could_ be an array. There does not appear to be a syntax error in the code.

And, sure enough, correcting the "error" still leaves the node thinking there is a problem but the code runs perfectly well.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ff7297cd67ed9ea2f1b5c085d5c3d4f35f93ac24.png)

Of course, so the runtime error was certainly correct because I didn't spot the extra level in the data (npm stats output). However, the node should not be marked as in error as far as I can tell.

Here is the function in full:

```auto
const out = {}

Object.keys(msg.payload).forEach( package => {
    
    out[package] = {}
    
    let first = false
    
    msg.payload[package].downloads.forEach( entry => {
        
        // Loose any zeros until the first download
        if ( first === false ) {
            if ( entry.downloads === 0 ) return
            else first = true
        }
        
        out[package][entry.day] = {
            'date': entry.day,
            'downloads': entry.downloads,
        }
        
    })
})

msg.payload = out

return msg;

```

I've not touched the Setup or Close parts or any other part of the function node.

Multiple ctrl-f5's to clear the caches didn't make a difference.

I can confirm that I don't get that error in v1.2 beta.

I also tried removing the flow, deploying then copy/paste a working version of the flow from my 1.2 beta instance. This successfully deploys with no error. **However** , if I then open the function node and add a space to the end of the first line, the error re-appears.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [1 October 2020 16:54 UTC](https://discourse.nodered.org/t/odd-problem-with-function-node-in-v1-1-3-bug/33636/2 "2020-10-01T16:54:48Z")

</div>

I replied in the previous thread, but it appears to have all been deleted, so has been lost.

In my reply I linked to another discussion that explains what you are seeing:

> As part of another fix (discussed [here](https://discourse.nodered.org/t/function-node-issues-invalid-properties-noerr-chrome-closing-editor-while-in-setup-or-close-tab/33128/8) with an explanation), some code was added to ensure ace errors would always be displayed (as they could sometimes be reported against line numbers outside of your actual code).

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [1 October 2020 16:57 UTC](https://discourse.nodered.org/t/odd-problem-with-function-node-in-v1-1-3-bug/33636/3 "2020-10-01T16:57:46Z")

</div>

Sorry Nick, my fault for trying to tidy up something that clearly wasn't related to the new beta.

OK, so this is a known problem. It does appear to be fixed in 1.2 beta.

---

<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: [15 October 2020 16:57 UTC](https://discourse.nodered.org/t/odd-problem-with-function-node-in-v1-1-3-bug/33636/4 "2020-10-15T16:57:52Z")

</div>

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