Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
codac opened this issue Oct 12, 2021 · 7 comments
Closed

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

codac opened this issue Oct 12, 2021 · 7 comments

Comments

@codac
Copy link

codac commented Oct 12, 2021

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
Copy link
Owner

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
Copy link
Collaborator

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
Copy link
Collaborator

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

@73cirdan
Copy link
Collaborator

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

@73cirdan
Copy link
Collaborator

73cirdan commented May 25, 2022

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 added a commit to 73cirdan/MMM-Formula1 that referenced this issue May 25, 2022
Signed-off-by: 73cirdan <73cirdan@gmail.com>
@73cirdan
Copy link
Collaborator

added pullrequest #40 to fix this issue

73cirdan added a commit to 73cirdan/MMM-Formula1 that referenced this issue May 25, 2022
issue ianperrin#33 - rewrote setTimeout call
ianperrin added a commit that referenced this issue May 27, 2022
issue #33 - rewrote setTimeout call
@ianperrin
Copy link
Owner

Thanks @73cirdan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants