Page MenuHomePhabricator

Uncaught TypeError: Cannot read property 'getItem' of null
Closed, ResolvedPublic

Description

2030 errors were thrown on mobile French Wikipedia in the last 12 hrs. This is extremely high - in fact is occurring more than any other error.

The banner looks like it was turned on at 4pm UTC yesterday.

Screen Shot 2020-10-01 at 2.33.47 PM.png (382×2 px, 64 KB)

Debugging is tricky, but I strongly believe this relates to a new campaign on French Wikipedia. The error is likely preventing the banner from displaying.

This error possibly relates to:
https://meta.wikimedia.org/wiki/Special:CentralNoticeBanners/edit/B2021_1002_frFR_m_p1_lg_txt_swap

which uses localStorage without any kind of feature detection.

Acceptance criteria

  • The bug is fixed
  • An update is made to the banner loader such that it's easier to identify errors coming from banners. I would recommend a named function e.g. insertCentralNoticeBannerHTML(); so that this appears in the stacktrace
at HTMLDocument.<anonymous>  <anonymous>:1863:41
at mightThrow  URL1:161:149
at process  URL1:161:808

URL1: https://fr.m.wikipedia.org/w/load.php?lang=fr&modules=ext.centralNotice.bannerHistoryLogger%2CchoiceData%2Cdisplay%2CgeoIP%2CimpressionDiet%2CkvStore%2ClargeBannerLimit%2ClegacySupport%2CstartUp%7Cext.centralauth.centralautologin%7Cext.eventLogging%2CnavigationTiming%2Cpopups%2CwikimediaEvents%7Cext.growthExperiments.SuggestedEditSession%7Cext.quicksurveys.init%2Clib%7Cext.relatedArticles.readMore.bootstrap%2Cgateway%7Cjquery%2Coojs%2Coojs-router%2Coojs-ui-core%2Coojs-ui-widgets%2Csite%7Cjquery.client%2Ccookie%2Cthrottle-debounce%7Cmediawiki.String%2CTitle%2CUri%2Capi%2Cbase%2Ccldr%2Ccookie%2Cexperiments%2CjqueryMsg%2Clanguage%2Crouter%2Cstorage%2Ctemplate%2Cuser%2Cutil%2Cviewport%7Cmediawiki.libs.pluralruleparser%7Cmediawiki.page.ready%7Cmediawiki.page.watch.ajax%7Cmediawiki.template.mustache%7Cmediawiki.ui.anchor%7Cmobile.init%2Cstartup%7Cmobile.messageBox.styles%7Cmobile.ooui.icons%7Cmobile.pagelist.styles%7Cmobile.pagesummary.styles%7Cmobile.placeholder.images%7Cmobile.startup.images%7Cmw.externalguidance.init%7Coojs-ui-core.icons%2Cstyles%7Coojs-ui-widgets.icons%7Coojs-ui.styles.indicators%7Cskins.minerva.icons.images.scripts%7Cskins.minerva.icons.images.scripts.misc%7Cskins.minerva.icons.page.issues.default.color%7Cskins.minerva.icons.page.issues.medium.color%7Cskins.minerva.icons.page.issues.uncolored%7Cskins.minerva.options%2Cscripts%7Cuser.defaults&skin=minerva&version=1jnxh
`

Event Timeline

Jdlrobson triaged this task as Unbreak Now! priority.Oct 1 2020, 9:36 PM

Possibly not unbreak now, but not sure as I don't know much about this banner campaign. Hopefully, someone in fundraising can confirm and update accordingly.

Given this doesn't concern production code this doesn't block the current deployment.

I'm also seeing the error NS_ERROR_FILE_CORRUPTED: on French Wikipedia which is likely related based on the timeframe.
https://logstash.wikimedia.org/app/kibana#/doc/logstash-*/logstash-2020.10.01/clienterror/?id=AXTl-f50LNRtRo5XPxEt

Pcoombe lowered the priority of this task from Unbreak Now! to High.Oct 1 2020, 10:47 PM

Thanks for spotting this @Jdlrobson. We did indeed launch our France campaign at 4pm UTC. 2000 errors is actually pretty small in the context of how many banners we're showing, but it's great that we can now catch these things. I've split out T264375: Make it easier to identify client side errors from CentralNotice banners in logs as a separate task since that will need CentralNotice work rather than just editing our banners.

For now I've just removed this particular bit of code from all our banners which are live, since none of them are actually making use of it. example diff. Leaving this task open to add proper feature detection in case we do want to use this code in other banners.

Nice! I can confirm the drop off!

Screen Shot 2020-10-01 at 4.38.54 PM.png (518×2 px, 82 KB)

Thanks for the bug fix.

I'm happy to help you setup a dashboard once we have a reliable way to detect these errors from a stack trace :)

Pcoombe claimed this task.

I updated our banners which do use this to add some feature detection. This should deal with the NS_ERROR_FILE_CORRUPTED issue too, which appears to be a Firefox issue: https://stackoverflow.com/questions/18877643/error-in-local-storage-ns-error-file-corrupted-firefox/26371494

Thanks @Ejegg for the code suggestion!

if ( localStorage ) {
    try {
        // TODO: make this general for any identifier, not just 2020
        var lsName = 'CentralNoticeKV|global|impression_diet_bannercount_fundraiser_2020';
        var diet = JSON.parse( localStorage.getItem( lsName ) );
        if ( diet ) {
            var seenCount = diet.val.seenCount;
            $( '.frb-replace-seenCount' ).text( seenCount );
            $( '.frb-replace-seenCount-ordinalNum' ).text( ordinalNums[ seenCount ] );
            $( '.frb-replace-seenCount-ordinalWord' ).text( ordinalWords[ seenCount ] );
        }
    } catch ( ex ) {
        // do nothing - localStorage is configured not to let us read it
    }
}