Page MenuHomePhabricator

TypeError: lists[i] is undefined at mw.uls.getFrequentLanguageList
Closed, ResolvedPublic

Description

https://logstash.wikimedia.org/app/kibana#/doc/logstash-*/logstash-2020.10.09/clienterror/?id=AXUOM4zg2lgCwKx71inp

at mw.uls.getFrequentLanguageList URL1:124:131
at getCommonLanguages URL1:126:969
at CompactInterlanguageList.prototype.compact URL1:130:950
at CompactInterlanguageList.prototype.getCompactList URL1:130:330
at CompactInterlanguageList.prototype.init URL1:127:834
at createCompactList URL1:133:197
at mightThrow URL1:194:149
at resolve/</process< URL1:194:808at mw.uls.getFrequentLanguageList URL1:124:131
at getCommonLanguages URL1:126:969
at CompactInterlanguageList.prototype.compact URL1:130:950
at CompactInterlanguageList.prototype.getCompactList URL1:130:330
at CompactInterlanguageList.prototype.init URL1:127:834
at createCompactList URL1:133:197
at mightThrow URL1:194:149
at resolve/</process< URL1:194:808

URL1: https://ru.wikipedia.org/w/load.php?lang=ru&modules=ext.centralNotice.choiceData%2Cdisplay%2CgeoIP%2CimpressionDiet%2CkvStore%2CstartUp%7Cext.centralauth.centralautologin%7Cext.cite.ux-enhancements%7Cext.cx.eventlogging.campaigns%7Cext.eventLogging%2CnavigationTiming%2Cpopups%2CwikimediaEvents%7Cext.flaggedRevs.advanced%7Cext.growthExperiments.SuggestedEditSession%7Cext.quicksurveys.init%2Clib%7Cext.uls.common%2Ccompactlinks%2Cinit%2Cinterface%2Cpreferences%2Cwebfonts%7Cjquery%2Coojs%2Coojs-router%2Coojs-ui-core%2Coojs-ui-widgets%2Csite%7Cjquery.client%2Ccookie%2CtextSelection%7Cjquery.uls.data%7Cmediawiki.String%2CTitle%2CUri%2Capi%2Cbase%2Ccldr%2Ccookie%2Cexperiments%2CjqueryMsg%2Clanguage%2Cstorage%2Cuser%2Cutil%2Cviewport%7Cmediawiki.editfont.styles%7Cmediawiki.libs.pluralruleparser%7Cmediawiki.page.ready%7Cmediawiki.ui.button%2Cicon%7Cmmv.bootstrap%2Chead%7Cmmv.bootstrap.autostart%7Coojs-ui-widgets.icons%7Cskins.vector.legacy.js%7Cuser.defaults&skin=vector&version=a2qv7
URL2: https://ru.wikipedia.org/w/load.php?lang=ru&modules=ext.centralNotice.choiceData%2Cdisplay%2CgeoIP%2CimpressionDiet%2CkvStore%2CstartUp%7Cext.centralauth.centralautologin%7Cext.cite.ux-enhancements%7Cext.cx.eventlogging.campaigns%7Cext.eventLogging%2CnavigationTiming%2Cpopups%2CwikimediaEvents%7Cext.flaggedRevs.advanced%7Cext.growthExperiments.SuggestedEditSession%7Cext.quicksurveys.init%2Clib%7Cext.uls.common%2Ccompactlinks%2Cinit%2Cinterface%2Cpreferences%2Cwebfonts%7Cjquery%2Coojs%2Coojs-router%2Coojs-ui-core%2Coojs-ui-widgets%2Csite%7Cjquery.client%2Ccookie%2CtextSelection%7Cjquery.uls.data%7Cmediawiki.String%2CTitle%2CUri%2Capi%2Cbase%2Ccldr%2Ccookie%2Cexperiments%2CjqueryMsg%2Clanguage%2Cstorage%2Cuser%2Cutil%2Cviewport%7Cmediawiki.editfont.styles%7Cmediawiki.libs.pluralruleparser%7Cmediawiki.page.ready%7Cmediawiki.ui.button%2Cicon%7Cmmv.bootstrap%2Chead%7Cmmv.bootstrap.autostart%7Coojs-ui-widgets.icons%7Cskins.vector.legacy.js%7Cuser.defaults&skin=vector&version=a2qv7:194:808at mw.uls.getFrequentLanguageList https://ru.wikipedia.org/w/load.php?lang=ru&modules=ext.centralNotice.choiceData%2Cdisplay%2CgeoIP%2CimpressionDiet%2CkvStore%2CstartUp%7Cext.centralauth.centralautologin%7Cext.cite.ux-enhancements%7Cext.cx.eventlogging.campaigns%7Cext.eventLogging%2CnavigationTiming%2Cpopups%2CwikimediaEvents%7Cext.flaggedRevs.advanced%7Cext.growthExperiments.SuggestedEditSession%7Cext.quicksurveys.init%2Clib%7Cext.uls.common%2Ccompactlinks%2Cinit%2Cinterface%2Cpreferences%2Cwebfonts%7Cjquery%2Coojs%2Coojs-router%2Coojs-ui-core%2Coojs-ui-widgets%2Csite%7Cjquery.client%2Ccookie%2CtextSelection%7Cjquery.uls.data%7Cmediawiki.String%2CTitle%2CUri%2Capi%2Cbase%2Ccldr%2Ccookie%2Cexperiments%2CjqueryMsg%2Clanguage%2Cstorage%2Cuser%2Cutil%2Cviewport%7Cmediawiki.editfont.styles%7Cmediawiki.libs.pluralruleparser%7Cmediawiki.page.ready%7Cmediawiki.ui.button%2Cicon%7Cmmv.bootstrap%2Chead%7Cmmv.bootstrap.autostart%7Coojs-ui-widgets.icons%7Cskins.vector.legacy.js%7Cuser.defaults&skin=vector&version=a2qv7

Event Timeline

It's quite odd. This happens when checking various values returned from functions that find common languages. As far as I can see all of them return arrays, even if empty. Perhaps there are some edge cases in some browsers with handling Accept-Language or local storage, which causes the value to be undefined. I tried to cause in Chrome and Firefox and couldn't (didn't check IE, but the bug appears to have happened in Firefox).

In any case, I'll send a simple patch that checks the validity of the array member, and I think it will prevent this unlikely bug. Other suggestions are welcome.

Change 636429 had a related patch set uploaded (by Amire80; owner: Amire80):
[mediawiki/extensions/UniversalLanguageSelector@master] Add a check that list member is valid in mw.uls.getFrequentLanguageList

https://gerrit.wikimedia.org/r/636429

I suspect the issue is that $.uls.data.getLanguagesInTerritory claims to return string[] but it can actually return undefined if there is no entry inside $.uls.data.territories[ territory ] $.uls.data.getLanguagesInTerritory('dddd') returns undefined for example.

What's possibly happening here is the country code has no entry.
Since the country code comes from window.Geo which comes from a cookie, maybe that itself is undefined or an unlisted country. It might be possible to use the IP address on the bug report to reverse engineer what window.Geo contains if you are interested.

It's also possible that window.Geo is undefined.

window.Geo = { country: 'ru' }
mw.uls.getCountryCode() // returns ru
$.uls.data.getLanguagesInTerritory('ru') // returns undefined
mw.uls.getFrequentLanguageList() // throws error

Change 641152 had a related patch set uploaded (by Amire80; owner: Amire80):
[mediawiki/extensions/UniversalLanguageSelector@master] Update jquery.uls from upstream

https://gerrit.wikimedia.org/r/641152

Change 636429 abandoned by Amire80:
[mediawiki/extensions/UniversalLanguageSelector@master] Add a check that list member is valid in mw.uls.getFrequentLanguageList

Reason:

https://gerrit.wikimedia.org/r/636429

Change 641152 merged by jenkins-bot:
[mediawiki/extensions/UniversalLanguageSelector@master] Update jquery.uls from upstream

https://gerrit.wikimedia.org/r/641152