"Too many errors" in function node, but works ok

Following on from another thread @Huda has a Function node that works correctly but in the node-red editor it shows a yellow warning triangle which shows the error "Too many errors 70% scanned". Google suggested that this could be caused by warnings which were suppressed by the particular use case of the syntax checker. However I have fed this into an only jshint checker and it shows no problems. I thought I had seen this problem discussed here previously but I can't find it. Here is the function, it shows the warning at line 100. I am using node-red 1.2.2

//variables to be used to seperate morse words.
var word = '';
var morseText = [];

//For every letter in the received message
for (var letter=0; letter<msg.payload.length; letter++)
{
    switch (msg.payload[letter])
    {//if it is part of a word
        case '.':
        case '-':
        case '>':
            word = word + msg.payload[letter]; //Then add it to the variable word
             break;
        case '<': //if it is the end of word signal
            morseText.push(word); //First, add the word to the morseText array.
            morseText.push('<'); //Then, add the signal.
            word = ""; //Finally, clear the word variable to start holding a new word.
            break;
        default:
            break;
    }
}

//variables to be used to transform morse words to english text.
var englishText = '';
var morseLetter = '';

//For every morse word saved in morseText array
for (var i =0; i<morseText.length; i++)
{
    var morseWord = morseText[i];
    //Loop through the morse signs in the word
    for (var sign =0; sign<morseWord.length; sign++)
    { 
        switch (morseWord[sign])
        {
            //if the sign is a dit or dah
            case '.':
            case '-':
                morseLetter = morseLetter + morseWord[sign];  //then add it as part of a letter.
                break;
            //if the sign is signaling the end of a word
            case '<':
                englishText = englishText + ' '; //then add a space.
                morseLetter = ''; //and clear the the letter variable to accept letters from the next word.
                break;
            //if the sign is signaling the end of the letter  
            case '>':
                //then figure out what that letter is in English
                switch (morseLetter)
                {
                    case '.-':
                        englishText = englishText + 'a';
                        break;
                    case '-...':
                        englishText = englishText + 'b';
                         break;
                    case '-.-.':
                        englishText = englishText + 'c';
                        break;
                    case '-..':
                        englishText = englishText + 'd';
                        break;
                     case '.':
                        englishText = englishText + 'e';
                        break;
                    case '..-.':
                        englishText = englishText + 'f';
                        break;
                    case "--.":
                        englishText = englishText + "g";
                        break;
                    case '....':
                        englishText = englishText + 'h';
                        break;
                    case '..':
                        englishText = englishText + 'i';
                        break;
                    case '.---':
                        englishText = englishText + 'j';
                        break;
                    case '-.-':
                        englishText = englishText + 'k';
                        break;
                    case '.-..':
                        englishText = englishText + 'l';
                        break;
                    case '--':
                        englishText = englishText + 'm';
                        break;
                    case '-.':
                        englishText = englishText + 'n';
                        break;
                    case '---':
                        englishText = englishText + 'o';
                        break;
                    case '.--.':
                        englishText = englishText + 'p';
                        break;
                    case '--.-':
                        englishText = englishText + 'q';
                        break;
                    case  '.-.':
                        englishText = englishText + 'r';
                        break;
                    case '...':
                        englishText = englishText + 's';
                        break;
                    case '-':
                        englishText = englishText + 't';
                        break;
                    case '..-':
                        englishText = englishText + 'u';
                        break;
                     case '...-':
                        englishText = englishText + 'v';
                        break;
                    case '.--':
                        englishText = englishText + 'w';
                        break;
                    case '-..-':
                        englishText = englishText + 'x';
                        break;
                    case '-.--':
                        englishText = englishText + 'y';
                        break;
                    case '--..':
                        englishText = englishText + 'z';
                        break;
                    default: 
                        englishText = englishText;
                        break;
                }
                morseLetter = ''; //and clear the the letter variable to accept the next letter.
                break;
            default: 
        }
    }
}
msg.payload = englishText;
return msg;
1 Like

Out of interest, this doesnt happen in my monaco branch so potentially its down to the updated ACE editor (I seem to remember ACE was updated very recently?)

Monaco

image

NOTE Also, it doesnt error in my dev version V1.2.0 with ACE editor or an older version V1.0.4.

EDIT - just updated my local repo and ran master (using ACE) still dont see this error. :thinking:

The plot thickens. I have another system also running node-red 1.2.2 and it doesn't happen there either. A difference is that it shows the problem on the one running nodejs 14.15.0 and not on the one running 10.22.1. Perhaps that is relevant.
@Steve-Mcl what versions of nodejs are you running? Also @Huda what version are you using? Run
node -v
to find out.

v12.16.1 on this machine Colin.

I will downgrade nodejs on the one running 14 and see if it goes away. That will have to be in the morning though.

1|Node-RED  | 30 Oct 21:39:13 - [info] Node-RED version: v1.2.0-beta.1
1|Node-RED  | 30 Oct 21:39:13 - [info] Node.js  version: v12.16.2
1|Node-RED  | 30 Oct 21:39:13 - [info] Windows_NT 10.0.19041 x64 LE

Shows the error. About to upgrade NR

1|Node-RED | 30 Oct 22:24:03 - [info] Node-RED version: v1.2.2
1|Node-RED | 30 Oct 22:24:03 - [info] Node.js  version: v12.16.2
1|Node-RED | 30 Oct 22:24:03 - [info] Windows_NT 10.0.19041 x64 LE

Still showing the error.

I spoke too soon.

master branch (V1.2.2)
image

this is running latest master (after npm update) - potentially suggesting I hadn't actually been running with latest ACE! Suggesting it is related to latest ACE update this issue rears its head? (was it V1.2.0 ACE was updated?)

(for reference, I dont see this issue in my monaco branch or V1.0.4)

Drat! Tried upgrading to NodeJS 14 and now:

PID:  22016
V8 Total Heap Size: 4129.17 MB
30 Oct 22:38:22 - [red] Uncaught Exception:
30 Oct 22:38:22 - TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (22016)
    at Object.writeFile (fs.js:1436:5)
    at C:\src\nr2\data\settings.js:35:8
    at FSReqCallback.oncomplete (fs.js:171:23)

Hmm, need to rebuild probably.

Oh dear, rebuilding everything didn't work.

Right, fixed. something changed between node v12 and v14.

But still showing the error in the function node.

I can reproduce this as well. Version of node.js will be irrelevant - all of the work is being done in the browser.

Can't see anything immediately obvious in that code. Will need digging into to see what the errors actually are.

If someone wanted to raise an issue then it won't get forgotten about. If someone wanted to dive in and figure out what's causing it - all the better.

It seems I have v14.15.0. Thank you all for trying to help!

When removing case statements from the switch the error disappears, in my case when there is just 11 left plus the default (Node-RED 1.2.2)

I have the same in some of my function nodes for very long (several years) in all versions of NR but the code has never failed from functionality point of view. Here is my code that will give you the same error indication. Strange thing is that in NR 1.1.2 the error is indicated at line 118, 57% scanned but in NR 1.2.2 it is already at line 64, 31% scanned

Maybe nothing wrong with the code, maybe the scanner runs into an overflow of some kind if you have too much code inside a function node??

// initialise the variables if they doesn't exist already
context.set('latestMode',msg.payload);
context.set('lastMessages',context.get('lastMessages')||null);
var myMsg = null;    
var msg1 = '';
var msg2 = '';
var msg3 = '';
var msg4 = '';
var msg5 = '';
var msg6 = '';
var msg7 = '';
var msg8 = '';
var msg9 = '';
var condition = context.get('latestMode');
var hday = '';
var d = new Date();
var wday = d.getDay();
var month = d.getMonth()+1;
if (month < 10) {
    month = '0'+ month.toString();
}
var day = d.getDate();
if (day < 10) {
    day = '0'+ day.toString();
}
d.setDate(d.getDate() + 1);
var month_tomorrow = d.getMonth()+1;
if (month_tomorrow < 10) {
    month_tomorrow = '0'+ month_tomorrow.toString();
}
var day_tomorrow = d.getDate();
if (day_tomorrow < 10) {
    day_tomorrow = '0'+ day_tomorrow.toString();
}
var td = month.toString()+day.toString();
var tm = month_tomorrow.toString()+day_tomorrow.toString();
if(condition!=='away' && condition!=='vacation'){
    if (global.get('myHolidays').indexOf(tm)>-1 && global.get('myHolidays').indexOf(td)<0){
        if(wday !== 0 && wday !== 6){
            condition = 'holiday_tomorrow';
        }
    }
    if (global.get('myHolidays').indexOf(tm)>-1 && global.get('myHolidays').indexOf(td)>-1){
        condition = 'holiday_today';
    }
    if (global.get('myHolidays').indexOf(tm)<0 && global.get('myHolidays').indexOf(td)>-1){
        hday = 'h_ends';
        if(wday < 5){
            condition = 'holiday_ends';
        }
        if(wday === 5){
            condition = 'holiday_today';
        }        
    }
}
switch (condition) {
    case 'holiday_today':
    msg1 = { payload:'stop' };
    msg2 = { payload:'stop' };
    msg3 = { payload:'stop' };
    msg4 = { payload:'stop' };
    msg5 = { payload:'stop' };
    msg6 = { payload:'stop' };
    msg7 = { payload:'auto' };
    msg8 = { payload:'stop' };
    msg9 = { payload:'stop' };
    hday = 'Holiday today';
    myMsg = 0;
    context.set('lastMessages',myMsg);
    node.send([msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9]);
    break;
    case 'holiday_tomorrow':
    msg1 = { payload:'stop' };
    msg2 = { payload:'stop' };
    msg3 = { payload:'stop' };
    msg4 = { payload:'stop' };
    msg5 = { payload:'stop' };
    msg6 = { payload:'stop' };
    msg7 = { payload:'stop' };
    msg8 = { payload:'auto' };
    msg9 = { payload:'stop' };
    hday = 'Holiday tomorrow';
    myMsg = 1;
    context.set('lastMessages',myMsg);
    node.send([msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9]);
    break;
    case 'holiday_ends':
    msg1 = { payload:'stop' };
    msg2 = { payload:'stop' };
    msg3 = { payload:'stop' };
    msg4 = { payload:'stop' };
    msg5 = { payload:'stop' };
    msg6 = { payload:'stop' };
    msg7 = { payload:'stop' };
    msg8 = { payload:'stop' };
    msg9 = { payload:'auto' };
    hday = 'Holiday ends today';
    myMsg = 2;
    context.set('lastMessages',myMsg);
    node.send([msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9]);
    break;
    case 'auto':
    msg1 = { payload:'auto' };
    msg2 = { payload:'auto' };
    msg3 = { payload:'auto' };
    msg4 = { payload:'auto' };
    msg5 = { payload:'stop' };
    msg6 = { payload:'stop' };
    msg7 = { payload:'stop' };
    msg8 = { payload:'stop' };
    msg9 = { payload:'stop' };
    if(hday === 'h_ends'){
        hday = 'Auto(Holiday Ends)';
    }
    else{
        hday = 'Automatic';
    }
    myMsg = 3;
    context.set('lastMessages',myMsg);
    node.send([msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9]);
    break;
    case 'on':
    msg1 = { payload:'on' };
    msg2 = { payload:'stop' };
    msg3 = { payload:'stop' };
    msg4 = { payload:'stop' };
    msg5 = { payload:'stop' };
    msg6 = { payload:'stop' };
    msg7 = { payload:'stop' };
    msg8 = { payload:'stop' };
    msg9 = { payload:'stop' };
    hday = 'On';
    myMsg = 4;
    context.set('lastMessages',myMsg);
    node.send([msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9]);
    break;
    case 'off':
    msg1 = { payload:'off' };
    msg2 = { payload:'stop' };
    msg3 = { payload:'stop' };
    msg4 = { payload:'stop' };
    msg5 = { payload:'stop' };
    msg6 = { payload:'stop' };
    msg7 = { payload:'stop' };
    msg8 = { payload:'stop' };
    msg9 = { payload:'stop' };
    hday = 'Off';
    myMsg = 5;
    context.set('lastMessages',myMsg);
    node.send([msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9]);
    break;
    case 'manual off':
    msg1 = { payload:'manual off' };
    msg2 = { payload:'stop' };
    msg3 = { payload:'stop' };
    msg4 = { payload:'stop' };
    msg5 = { payload:'stop' };
    msg6 = { payload:'stop' };
    msg7 = { payload:'stop' };
    msg8 = { payload:'stop' };
    msg9 = { payload:'stop' };
    hday = 'Manual off';
    myMsg = 6;
    context.set('lastMessages',myMsg);
    node.send([msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9]);
    break;
    case 'vacation':
    msg1 = { payload:'stop' };
    msg2 = { payload:'stop' };
    msg3 = { payload:'stop' };
    msg4 = { payload:'stop' };
    msg5 = { payload:'auto' };
    msg6 = { payload:'stop' };
    msg7 = { payload:'stop' };
    msg8 = { payload:'stop' };
    msg9 = { payload:'stop' };
    hday = 'Vacation';
    myMsg = 7;
    context.set('lastMessages',myMsg);
    node.send([msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9]);
    break;
    case 'away':
    msg1 = { payload:'stop' };
    msg2 = { payload:'stop' };
    msg3 = { payload:'stop' };
    msg4 = { payload:'stop' };
    msg5 = { payload:'stop' };
    msg6 = { payload:'auto' };
    msg7 = { payload:'stop' };
    msg8 = { payload:'stop' };
    msg9 = { payload:'stop' };
    hday = 'Away';
    myMsg = 8;
    context.set('lastMessages',myMsg);
    node.send([msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9]);
    break;
    default:
    hday = 'Unknown';
    break;
}
node.status({
	    text : hday
});

Here we go, this code indicates the same error, line 50 in my case. Believe the code is correct, must be something with the parser. Delete some lines and the error goes away

let p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;
p = msg.payload;

I have raised an issue for this

1 Like

@krambriw I have added your example to the issue.

1 Like

@Colin,
Thanks a lot! I do believe so too, it's not the code that is faulty. As I mentioned I have (too large) code running flawless for years

Your memory is with you for sure, it has been discussed long time ago, but I think it was back in the old days before we moved over to discourse

I think you are probably correct.

You are correct: https://groups.google.com/g/node-red/c/l9dlJzoxBOk

I am seeing the same problem with different code. There seems to be an issue once the code is over a certain length. One interim work around is to use the line:
/*jshint maxerr: 100000 */

@whatsupskip could you add the comments to the GitHub issue please so that they are available for anyone looking at the issue.