naofireblade / homebridge-weather-plus

A comprehensive weather plugin for homebridge.
MIT License
311 stars 61 forks source link

Cannot read properties of undefined (reading 'list') #271

Closed zanethefox closed 4 months ago

zanethefox commented 10 months ago

Hello, I just noticed my Homebridge install crashed due to an Error with the plugin.

Below is a log, has anyone got this error before? I am also using the API 2.5.

Is it possible to catch this error and handle it gracefully so it doesn't cause the home bridge to crash?

[04/09/2023, 20:29:25] TypeError: Cannot read properties of undefined (reading 'list') at /var/lib/homebridge/node_modules/homebridge-weather-plus/apis/openweathermap.js:108:46 at Request._callback (/var/lib/homebridge/node_modules/homebridge-weather-plus/apis/openweathermap.js:406:5) at self.callback (/var/lib/homebridge/node_modules/homebridge-weather-plus/node_modules/request/request.js:185:22) at Request.emit (node:events:513:28) at Request.onRequestError (/var/lib/homebridge/node_modules/homebridge-weather-plus/node_modules/request/request.js:877:8) at ClientRequest.emit (node:events:513:28) at TLSSocket.socketErrorListener (node:_http_client:502:9) at TLSSocket.emit (node:events:513:28) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) [04/09/2023, 20:29:25] Got SIGTERM, shutting down Homebridge... [04/09/2023, 20:29:30] [HB Supervisor] Homebridge Process Ended. Code: 143, Signal: null [04/09/2023, 20:29:35] [HB Supervisor] Restarting Homebridge... [04/09/2023, 20:29:35] [HB Supervisor] Starting Homebridge with extra flags: -I -P /var/lib/homebridge/node_modules --strict-plugin-resolution [04/09/2023, 20:29:35] [HB Supervisor] Started Homebridge v1.6.1 with PID: 9237

dacarson commented 9 months ago

Looking at the code, without reproducing it myself, this does definitely look like a bug.

In the update(forecastDays, callback) function in openweathermap.js, it tries to fetch the current forecast with the 2.5 API:

// Old api requires an extra call to get the forecast
if (this.api === "2.5")
{
    this.getWeatherData(this.apiBaseURL + "/data/2.5/forecast", (error, result) =>
    {
        this.generateForecasts(weather, result["list"], result["city"]["timezone"], callback);
    });
}

In the function getWeatherData(), if there is a requestError it calls the callback with a null result object, aka callback(requestError);

Then when it tries to process the response: this.generateForecasts(weather, result["list"], result["city"]["timezone"], callback); it does not take into account that an error may have occurred and the result object is null.

dacarson commented 9 months ago

I have a fix that would handle this error gracefully, aka log it and move on. Can I send you an updated openweathermap.js file to test?

gsampieri commented 9 months ago

Hello, I have the same issue that occasionally occurs on version 3.2.11. I would appreciate the update of the openweathermap.js file to test ! Thank you!

dacarson commented 5 months ago

Fixed and landed in #276

dacarson commented 4 months ago

Are we able to close this now?

zanethefox commented 4 months ago

Hello thanks so much for the work! I missed the notifications unfortunately. Yes, we can close this now, thanks again!