maxlath / wikibase-sdk

JS utils functions to query a Wikibase instance and simplify its results
MIT License
325 stars 47 forks source link

Uncaught (in promise) Error: missing a title #86

Open sebilasse opened 1 year ago

sebilasse commented 1 year ago

redaktor is currently learning the planet earth including administrative or touristic hierarchies and connecting OSM relation, wikidata id, geonames etc. When I looked for the following [ "Q1844", "Q49651", "Q49654", "Q49655", "Q49657", "Q49659", "Q49660", "Q49661", "Q49662", "Q4540", "Q49663", "Q27439086", "Q27439070", "Q4191863", "Q593158", "Q991615", "Q27439073", "Q816776" ] and used getManyEntities .then simplify [without options] then I got

error: Uncaught (in promise) Error: missing a title at Object.yr [as getSitelinkUrl] (https://esm.sh/v96/wikibase-sdk@8.0.5/deno/wikibase-sdk.js:4:5206)

I see that it is coming from simplify (which I'll try/catch too as workaround) in my code

fetch(wikibase-sdk-url, { headers }).then((r) => {
    if (!r.ok) resolve([]);
    return r.json();
  }).then((res: any) => {
    if (!res) resolve([]);
    const { entities } = res;
    resolve(wikidata.simplify.entities(entities));
  }).catch(() => {
    resolve([]);
  });
EdJoPaTo commented 1 year ago

As this library is completely without async / Promises the uncaught promise error is unrelated to this library. Using try catch and await is way easier to manage than your .then / .catch method chain.

try {
  const response = await fetch(url, {headers});
  const { entities } = await response.json();
  const simplified = wdk.simplify.entities(entities);
} catch {…}

Would be interesting which Q id exactly caused this to debug this.

sebilasse commented 1 year ago

Sorry, I do not understand. The import './simplify.js' is from this library.

If I give wikidata.simplify.entities(entities) the same statically, the error is the same. It is just an uncaught promise error cause it is in a promise.

EdJoPaTo commented 1 year ago

Yes, the simplifyEntities method is from this library but this library does not use any promise. Therefore it can not produce an uncaught promise which means the uncaught promise must be created somewhere else in your code or another library you use.

Personally I would rewrite your code with the await keyword and the try catch around it as I suspect a missing catch in there and it’s just way easier to read/understand. (Like the example in my last response)

I hope I could rephrase my response well enough?

EdJoPaTo commented 1 year ago

Ok, the title of this issue is very misleading. It’s not at all about the uncaught promise.

Can you specify which Item ID fails exactly? Also it looks like Deno is using a minified version without source map. So it’s not entirely clear where exactly it’s happening.