{"record":{"id":"542ca97538877a55","repo":"mvanhorn/last30days-skill","slug":"polymarket-event-was-not-found","errorCode":null,"errorMessage":"Polymarket event was not found","messagePattern":"Polymarket event was not found","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"skills/last30days/scripts/lib/polymarket.py","lineNumber":1001,"sourceCode":"        event = _pick_event(payload)\n    elif isinstance(payload, dict) and isinstance(payload.get(\"events\"), list):\n        event = _pick_event(payload.get(\"events\") or [])\n    else:\n        event = payload\n        if (\n            requested_slug is not None\n            and isinstance(event, dict)\n            and (\n                str(event.get(\"slug\") or \"\").strip() not in (\"\", requested_slug)\n                or (\n                    expected_id\n                    and str(event.get(\"id\") or \"\").strip() not in (\"\", expected_id)\n                )\n            )\n        ):\n            event = None\n    if not isinstance(event, dict):\n        raise KeyError(\"Polymarket event was not found\")\n    # Mixed events: an active event can carry resolved child markets whose\n    # high volume would win the parse and swap the outcome labels. Only fall\n    # back to closed markets when nothing is active (fully resolved event -\n    # the stale-odds transition verification exists to catch).\n    markets = event.get(\"markets\") or []\n    has_active = any(\n        isinstance(m, dict) and m.get(\"active\", True) and not m.get(\"closed\", False)\n        for m in markets\n    )\n    parsed = parse_polymarket_response(\n        {\"events\": [event]},\n        include_all_outcomes=True,\n        include_closed=not has_active,\n    )\n    if not parsed:\n        raise KeyError(\"Polymarket event is closed, unavailable, or malformed\")\n    refreshed = parsed[0]\n    values: dict[str, Any] = {}","sourceCodeStart":983,"sourceCodeEnd":1019,"githubUrl":"https://github.com/mvanhorn/last30days-skill/blob/c7460f6114449ddfe6ea3fc2f23c3d910c0e740c/skills/last30days/scripts/lib/polymarket.py#L983-L1019","documentation":"KeyError raised when the Gamma API call for the re-verification succeeded but the returned payload does not contain a usable event dict. This includes the case where the fetched event's slug or id does not match what was requested (the code nulls the event on identity mismatch) - i.e. the event was deleted, made private, or the id/slug drifted.","triggerScenarios":"GET {GAMMA_EVENTS_URL}/{id} or GET ?slug=... returns a payload whose events list is empty, or returns an event whose slug differs from requested_slug, or whose id differs from expected_id (the identity check at the top of the source region sets event = None). Any subsequent isinstance(event, dict) check fails and the KeyError fires.","commonSituations":"Resolving-markets events that Gamma removes after settlement; slug reuse where the slug now points to a different event; transient Gamma API degradation returning malformed envelopes; stale cached ids after Polymarket migrations.","solutions":["Treat as terminal for this datum: catch KeyError and surface the item as 'unresolvable' rather than retrying immediately","If retrying, use exponential backoff to ride out transient Gamma API issues","For resolved/delisted markets, refresh the item through the normal search flow to get a current event reference"],"exampleFix":"# before\nval = refetch_datum(item, key)\n\n# after\ntry:\n    val = refetch_datum(item, key)\nexcept KeyError:\n    mark_unresolvable(item)  # event gone or identity drifted","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    datum = refetch_datum(item, key)\nexcept KeyError as e:\n    if \"was not found\" in str(e):\n        mark_item_unresolvable(item)  # deleted/delisted/identity drift - terminal","preventionTips":["Skip re-verification for items older than the event's typical resolution horizon","Surface 'event no longer available' distinctly from transient network errors","Cache event ids rather than slugs as the primary long-term reference"],"tags":["polymarket","api","keyerror","verification"],"backgroundTag":null,"analyzedSha":"c7460f6114449ddfe6ea3fc2f23c3d910c0e740c","analyzedAt":"2026-08-15T03:34:49.540Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}