Node red update breaks node-red-google-notify

Hi, I have just updated from NR 21.0.1 to 21.0.3 and it won’t start, giving an error of:

[red] Uncaught Exception:
27 Feb 13:13:17 - [error] TypeError: Cannot read properties of undefined (reading 'toLowerCase')
    at /opt/node_modules/node-red-google-notify/node-red-google-notify.js:239:31
    at Array.forEach (<anonymous>)
    at Browser.<anonymous> (/opt/node_modules/node-red-google-notify/node-red-google-notify.js:235:25)
    at Browser.emit (node:events:508:28)
    at Browser._addService (/opt/node_modules/bonjour/lib/browser.js:109:8)
    at /opt/node_modules/bonjour/lib/browser.js:86:14
    at Array.forEach (<anonymous>)
    at /opt/node_modules/bonjour/lib/browser.js:84:15
    at Array.forEach (<anonymous>)
    at EventEmitter._onresponse (/opt/node_modules/bonjour/lib/browser.js:76:26)
    at EventEmitter.emit (node:events:508:28)
    at Socket.<anonymous> (/opt/node_modules/multicast-dns/index.js:49:43)
    at Socket.emit (node:events:508:28)
    at UDP.onMessage (node:dgram:992:8)
[13:13:17] INFO: Service Node-RED exited with code 1 (by signal 0)

I’m assuming that it’s something I’ve done in previous times, but I’m a bit surprised at this failure given that the change notes for 21.0.2 and 21.0.3 don’t mention any changes to the google-notify node.

Google tells me that I might be sending something unwanted to the node, but whatever it is 21.0.1 wasn’t too worried about it.
I’ve done some looking but can’t see anything obvious. I’ve also stringified the data going to the node, and checked for null, to no effect. In any case, surely bad data shouldn’t be an issue until the system is running?

The error is because you try to lowercase a string, but there is no string available.
Could it be that the string value can not be read from the source?

I have set things up so that an undefined or null value in msg.playMsg will be replaced with a default value. Still doesn’t work, plus I’m still trying to wrap my head around what’s changed.

You have updated the HA App for Node-RED, and the difference between 21.0.1 and 21.0.3 has few changes but does move Node-RED itself from 4.1.5 to 4.1.6.

The 4.1.6 release of Node-RED does not appear to have any significant changes, and nothing that appears to modify the run-time.

There are a lot of nodes available for Node-RED. The NR standard package for the editor/runtime includes the core nodes, which are part of each NR release. The HA App bundle adds in a few extra nodes. After that, you can add anything from the NR node library. Most of these are ‘contib’ nodes, or contributions from the community. Written by anyone, they are mostly written, supported for a bit, then abandoned. Beyond that, any changes long-term to Node-RED, or Node.JS on which NR runs, or to Home Assistant, or to the environment generally, may cause the node to fail. There are thousands of extra ‘contribution’ nodes, and no one is going to test any of these at every update to Node-RED or to the HA Node-RED App.

This node does not appear in the standard NR package, nor the HA App. It is also no longer supported, and has a big red-text warning in the GitHub repository. Therefore, any issues with this node are very much a case of ‘sort it out yourself’.

The error message you are seeing points directly to the source file at line 239, character 31, so easy enough to locate the GitHub repository, the code, and the offending part.

  function discoverIpAddresses(serviceType, discoveryCallback) {
    var ipaddresses = [];
    var bonjour = require('bonjour')();
    var browser = bonjour.find({
      type: serviceType
    }, function (service) {
      service.addresses.forEach(function (element) {
        if (element.split(".").length == 4) {
          const deviceTypeName = ""
            + service.txt.md
            + (service.txt.md.toLowerCase() != service.txt.fn.toLowerCase() ? "." + service.txt.fn : "");
          const label = deviceTypeName
            + " (" + element + ")";
          ipaddresses.push({
            label: label,
            device: deviceTypeName,
            value: element
          });
        }
      });

      //Add a bit of delay for all services to be discovered
      if (discoveryCallback)
        setTimeout(function () {
          discoveryCallback(ipaddresses);
        }, 2000);
    });
  }

I am certainly no expert in such code, but clearly the line

+ (service.txt.md.toLowerCase() != service.txt.fn.toLowerCase()

is failing where the method .toLowerCase() is being applied to the return from a bonjour call.

My guess is that this code is part of the node’s startup routine, where it uses bonjour to find services. The fact that this is run at startup, when the node first loads, probably means that Node-RED cannot load the node correctly, and hence Node-RED will fail to start. I think that your only immediate solution is to remove this node from the palette.

Interestingly, the bonjour JS code (loaded using ‘require’) was updated only two weeks ago from 3.5.0 (May 2016) to 3.5.1, so it might be possible that a change there has resulted in a different or null return from the API find call.

I note too that bonjour (js) was effectively replaced by bonjour-services, so this is an old node using an old library.

As Wally says - if the bonjour find returns nothing, then the code .lowercase will fail, and my assumption is that better code would have a ‘try’ and some form of error recovery…

Since HA has tts services using eg. cloud or google, I use Action tts.cloud targeted to my google device. You can therefore use an HA Action node to perform the required task in place of this node.

1 Like

Thanks for the good information Geoff.

After a coffee and a lie down, I finally managed to use the action nodes to set volume and then generate a TTS message.