ianperrin / MMM-Formula1

A MagicMirror Module for displaying Formula 1 driver and constructor standings.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: Cannot read property 'type' of undefined

codac opened this issue · comments

I'm getting the following error:

[12.10.2021 14:28.31.703] [ERROR] TypeError: Cannot read property 'type' of undefined
at Timeout.fetchStandings [as _onTimeout] (/opt/magic_mirror/modules/MMM-Formula1/node_helper.js:48:57)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)

Maybe not received as an result of a timeout. Anyways there should be an error handling for.

commented

Hi @codac

thanks for logging the issues. Unfortunately I’ve not been able to reproduce the error. Could you share your config and the version of the module you are using?

Thanks

Getting something similar, consequence is that the data is fetched normal, but first time update fails and data becomes stale. Will dive in, to explore the cause

1|mm  | [24.05.2022 12:38.11.647] [ERROR]
1|mm  | Whoops! There was an uncaught exception...
1|mm  | [24.05.2022 12:38.11.672] [ERROR]
1|mm  | TypeError: Cannot read properties of undefined (reading 'type')
1|mm  |     at Timeout.fetchStandings [as _onTimeout] (/home/pi/MagicMirror/modules/MMM-Formula1/node_helper.js:48:57)
1|mm  |     at listOnTimeout (node:internal/timers:557:17)
1|mm  |     at processTimers (node:internal/timers:500:7)
1|mm  | [24.05.2022 12:38.11.678] [ERROR]
1|mm  | MagicMirror² will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
1|mm  | [24.05.2022 12:38.11.680] [ERROR] If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues
1|mm  | [24.05.2022 12:38.11.685] [ERROR]
1|mm  | Whoops! There was an uncaught exception...
1|mm  | [24.05.2022 12:38.11.692] [ERROR]
1|mm  | TypeError: Cannot read properties of undefined (reading 'season')
1|mm  |     at Timeout.fetchSchedule [as _onTimeout] (/home/pi/MagicMirror/modules/MMM-Formula1/node_helper.js:63:83)
1|mm  |     at listOnTimeout (node:internal/timers:557:17)
1|mm  |     at processTimers (node:internal/timers:500:7)

My config.js

                {
                        module: 'MMM-Formula1',
                        classes: "default everyone",
                        position: 'top_right',
                        header: 'F1 Standings',
                        config: {
                                // Optional configuration options - see https://github.com/ianperrin/MMM-Formula1#configuration-options
                                calendar: true,
                                season: 2022,
                                maxRows: 6,
                                fade: false,
                        }
                },

added some logging. this.config is null, at the start of the fetch methods when called after the timeout...

It looks like after the timeout, the "this" object is a timeout object and not the nodehelper object anymore

Changed in the node_helper the fetchStandings and fetchSchedule methods in the same way:

      fetchStandings: function () {
               console.log(this.config);
               console.log(this.name + " is fetching " + this.config.type + " standings for the " + this.config.season + " season");
               const endpoint = this.config.type === "DRIVER" ? "getDriverStandings" : "getConstructorStandings";
               const season = (this.config.season === "current", new Date().getFullYear(), this.config.season);
               const self = this;
               f1Api[endpoint](season).then((standings) => {
                       console.log(this.name + " is returning " + this.config.type + " standings for the " + season + " season");
                       this.sendSocketNotification(this.config.type + "_STANDINGS", standings);
                       this.standingsTimerId = setTimeout(function () {self.fetchStandings(); }, this.config.reloadInterval);
               });
       },
``

added self=this and changed the call to the setTimeout method

added pullrequest #40 to fix this issue

commented

Thanks @73cirdan