GoogleCloudPlatform / node-red-contrib-google-cloud

Node-RED nodes for Google Cloud Platform
Apache License 2.0
90 stars 57 forks source link

GoogleCloudPubSubOutNode crashes Node-RED if connection fails #125

Open garnold opened 1 year ago

garnold commented 1 year ago

When GoogleCloudPubSubOutNode is initialized, an uncaught exception is thrown when creating the topicReady Promise causing Node-RED to fail to deploy the flow. An example would be if a non-existent topic name is provided. I believe this is because some of the async stuff going on behind the scenes in the API client. Adding a catch fixes the issue, but will cause a NPE when a msg is passed into the node:

        topicReady = new Promise((resolve, reject) => {
            pubsub.topic(config.topic).get().then((data) => {
                topic = data[0];
                node.status(STATUS_CONNECTED);
                resolve();
            }).catch((reason) => {
                node.status(STATUS_DISCONNECTED);
                node.error(reason);
                reject(reason);
            });
        }).catch((reason) => {
                node.status(STATUS_DISCONNECTED);
                node.error(reason);
        }); // topicReady

IMHO configuration errors should not result in exceptions during node initialization; instead, feedback should be provided to the flow and the node should be started in a non-functional state.