dijs / wiki

Wikipedia Interface for Node.js
MIT License
315 stars 61 forks source link

NPE in page.mainImage #72

Closed FriendOfTheNight closed 6 years ago

FriendOfTheNight commented 6 years ago

Getting several errors from page.mainImage function (trying to access imageinfo on undefined). I unminified and added a check to fix for now. npe-fix

dijs commented 6 years ago

Can you please provide a article this is happening on?

FriendOfTheNight commented 6 years ago

Here is a page that's causing it: https://en.wikipedia.org/wiki/Java_Classloader

I just took it out to recreate and the exact error is "TypeError: Cannot read property 'imageinfo' of undefined."

As far as I can tell it's happening for any article with no image. I'm searching for pages with wiki().search, then iterating over the page titles and getting the page with wiki().page, then calling page.mainImage on the page.

let pages = await wiki().search(searchQuery, numResults);
...
var page = await wiki().page(pages[i]);
var image = await page.mainImage();
...

Let me know if you need any more info.

Thanks, Brian

dijs commented 6 years ago

Good find. v4.5.2 has the fix.