spencermountain / wtf_wikipedia

a pretty-committed wikipedia markup parser
https://observablehq.com/@spencermountain/wtf_wikipedia
MIT License
770 stars 129 forks source link

first_word and trunc templates choke on some examples #528

Closed mx781 closed 1 year ago

mx781 commented 1 year ago
// first word
wtf.fetch("Formula One drivers from Finland", "en")
// trunc
wtf.fetch("2007 FIFA Women's World Cup Group A", "en")

@spencermountain reporting here in case you know the solution right away - if not, will dig into these myself soon

Full output:


//first word
TypeError: Cannot read properties of undefined (reading 'split')
    at first word (/foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:4782:18)
    at parseTemplate (/foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8416:34)
    at parseNested (/foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8700:26)
    at /foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8697:38
    at Array.forEach (<anonymous>)
    at parseNested (/foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8697:22)
    at /foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8697:38
    at Array.forEach (<anonymous>)
    at parseNested (/foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8697:22)
    at /foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8722:30

// trunc
TypeError: Cannot read properties of undefined (reading 'substr')
    at Object.trunc (/foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:4787:22)
    at parseTemplate (/foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8416:34)
    at parseNested (/foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8700:26)
    at /foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8697:38
    at Array.forEach (<anonymous>)
    at parseNested (/foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8697:22)
    at /foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8697:38
    at Array.forEach (<anonymous>)
    at parseNested (/foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8697:22)
    at /foo/node_modules/wtf_wikipedia/builds/wtf_wikipedia.cjs:8722:30
spencermountain commented 1 year ago

oof, a runtime error - you're on the ball. yeah! go for it - otherwise I can do it later this evening. thank you.

mx781 commented 1 year ago

For the first one it looks the issue is that the first word template has a F1Stat template nested inside it, which is not supported, so presumably it doesn't return anything useful. I guess this could be fixed with a if (str !== undefined) clause, but I reckon this could happen in many other templates that assume str is not undefined, so this would be a poor patch and should probably be handled in the "handled unknown template" logic?

mx781 commented 1 year ago

two more to add to the pile

// fails on percentage template
wtf.fetch("Sacramento Mountain Lions", "es")

// fails on min template
wtf.fetch("Phase finale du Championnat du monde masculin de handball 2019", "fr")
spencermountain commented 1 year ago

got em - fixed in 10.1.4 thank you for your help - please share any more that you find. These templates bugs are pretty whackamole. cheers