ianperrin / MMM-Formula1

A MagicMirror Module for displaying Formula 1 driver and constructor standings.
MIT License
30 stars 13 forks source link

TypeError: Cannot read property 'type' of undefined #33

Closed codac closed 2 years ago

codac commented 2 years ago

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.

ianperrin commented 2 years ago

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

73cirdan commented 2 years ago

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,
                        }
                },
73cirdan commented 2 years ago

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

73cirdan commented 2 years ago

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

73cirdan commented 2 years ago

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

73cirdan commented 2 years ago

added pullrequest #40 to fix this issue

ianperrin commented 2 years ago

Thanks @73cirdan