Magicmirror: Uncaught TypeError: Cannot read property dismiss of null (alert.js)

Created on 31 Mar 2018  路  12Comments  路  Source: MichMich/MagicMirror

I keep getting random events where the error is:

Uncaught TypeError: Cannot read property 'dismiss' of null

alert_bug

The error is coming from the Alert default module on Line 113, in alert.js:

    hide_alert: function(sender) {
        //Dismiss alert and remove from this.alerts
        this.alerts[sender.name].dismiss();  // <<========= LINE  113 !
        this.alerts[sender.name] = null;
        //Remove overlay
        var overlay = document.getElementById("overlay");
        overlay.parentNode.removeChild(overlay);
},

@MichMich
Does this have to be null or can it also be set to "" or something else?
Any ideas how to fix or work around this?

I'm surprised nobody else has reported this issue, so I want to eliminate that it is a problem with my module.

Most helpful comment

I really hoped someone would replace this 馃挬 code really fast 馃槄

All 12 comments

I tried to fix with some variations of this:

        //Dismiss alert and remove from this.alerts
//        if (this.alerts[sender.name] != null) {
            this.alerts[sender.name].dismiss();
            this.alerts[sender.name] = "";        // was null
 //       }

But it didn't work...and seem to need something else.

It's because a alert is dismissed which doesn't exist. Which module is firing the alerts? Might be worth checking that code as well.

It's our module MMM-Assistant, that seem to use Alerts to show pop-up screen results for Snowboy requests...

But, why didn't my if() statement work then? (Actually it seem to have worked, but then got another error message instead.)

if (this.alerts[sender.name]) { would cover null, undefined empty string and more

@fewieden Yeah, but I already tried that before the comments shown above, and it just propagated the error elsewhere... Seem to be some kind of race condition...

  • Why would something else be closing it? (Should a module close it's own?)

Or maybe I need to enclose the whole thing before the closing bracket?

what is the other error?

I think you need to put the dom actions into your if statement

var overlay = document.getElementById("overlay");
overlay.parentNode.removeChild(overlay);

if there is no alert to dismiss, there should also be no dom action.
if the overlay is not there, you're trying to access parentNode of null

Might be a good idea to check with @paviro, he made the alert module.

Oh man :D that was ages ago. I will have a look later today :)

@paviro It will hunt you for the rest of you life. ;)

I really hoped someone would replace this 馃挬 code really fast 馃槄

@E3V3A If that fix seems to work for you, feel free to send a PR. I'll merge it after all test's are finished.

Just tested, @fewieden suggestion fixed it. Now the question is why this happened in the first place.

Done, while you guys were chatting... ;)
https://github.com/MichMich/MagicMirror/pull/1248

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ConnorChristie picture ConnorChristie  路  7Comments

3vidar picture 3vidar  路  6Comments

Darkcast picture Darkcast  路  4Comments

matthieu994 picture matthieu994  路  7Comments

metalshreds picture metalshreds  路  6Comments