koala73/worldmonitor · error · Error
Wikidata request failed
Error message
Wikidata request failed
What it means
This is the exhausted-loop sentinel in queryWikidata: after all WIKIDATA_ATTEMPTS iterations, if no attempt returned bindings (each either failed HTTP and the last attempt rethrew, or JSON parsing failed and the last attempt swallowed/kept looping), the function throws generic Error 'Wikidata request failed'. It indicates the Wikidata lookup could not complete within the retry budget.
Source
Thrown at server/worldmonitor/intelligence/v1/get-country-facts.ts:178
} catch (error) {
if (attempt === WIKIDATA_ATTEMPTS - 1) throw error;
continue;
}
if (!response.ok) {
const retryable = response.status === 429 || response.status >= 500;
if (retryable && attempt < WIKIDATA_ATTEMPTS - 1) continue;
throw new Error(`Wikidata request failed with status ${response.status}`);
}
try {
const data = (await response.json()) as WikidataResponse;
return data.results?.bindings ?? [];
} catch (error) {
if (attempt === WIKIDATA_ATTEMPTS - 1) throw error;
}
}
throw new Error('Wikidata request failed');
}
function parseWikidataFacts(bindings: WikidataBinding[]): WikiResult | null {
if (bindings.length === 0) return null;
const firstLabel = (field: keyof WikidataBinding): string => {
for (const binding of bindings) {
const label = cleanLabel(binding[field]?.value);
if (label) return label;
}
return '';
};
const firstNumber = (field: 'population' | 'area'): number => {
for (const binding of bindings) {
const value = Number(binding[field]?.value);
if (Number.isFinite(value) && value > 0) return value;
}
return 0;View on GitHub (pinned to 9361220cc0)
Solutions
- Inspect upstream behavior during the incident; check https://www.wikidata.org status and whether responses are HTML error pages rather than JSON
- Increase WIKIDATA_ATTEMPTS and add backoff so transient outages fit within the retry budget
- Log the underlying parse/HTTP error per attempt so this generic error can be diagnosed
- Serve stale cached country facts (or a secondary source) when this error is caught
Example fix
} catch (error) {
if (attempt === WIKIDATA_ATTEMPTS - 1) throw error;
}
// after: record why each attempt failed
} catch (error) {
lastError = error;
if (attempt === WIKIDATA_ATTEMPTS - 1) throw new Error(`Wikidata request failed: ${String(error)}`);
} Defensive patterns
Strategy: fallback
Validate before calling
// Precheck connectivity/body shape before consuming attempts
const probe = await fetch(WIKIDATA_ENDPOINT, { method: 'HEAD' });
if (!probe.ok) useCachedFacts(); Type guard
function isWikidataExhausted(e: unknown): boolean {
return e instanceof Error && e.message === 'Wikidata request failed';
} Try / catch
try {
facts = await getCountryFacts(cc);
} catch (e) {
if (isWikidataExhausted(e)) return cachedOrEmptyFacts(cc);
throw e;
} Prevention
- Instrument each attempt to record whether HTTP or JSON parsing failed
- Increase WIKIDATA_ATTEMPTS / add backoff for outage windows
- Keep a last-known-good cache of country facts as a fallback source
- Alert on repeated exhausted-loop errors — they indicate sustained upstream failure
When it happens
Trigger: Every attempt fails: the last attempt's non-ok status rethrows the status error, or the final attempt's response.json() throws (invalid/truncated body) and control falls out of the loop, reaching this throw.
Common situations: Wikidata returning HTML error pages or empty bodies during an outage so JSON parsing fails on every attempt; sustained rate limiting across the whole retry window; network issues truncating responses; retry count too low for a flaky endpoint.
Related errors
- Wikidata request failed with status ${response.status}
- ${label} HTTP ${response.status}
- relay returned ${resp.status}
- relay returned ${resp.status}
AI-assisted analysis of koala73/worldmonitor@9361220cc0 (2026-09-01).
Data as JSON: /api/errors/ca5f5bfd0e7838ae.
Report an issue: GitHub.