{"record":{"id":"f00f43b1a03f57c2","repo":"geekcomputers/Python","slug":"the-deck-is-empty-cannot-draw-more-cards","errorCode":null,"errorMessage":"The deck is empty; cannot draw more cards","messagePattern":"The deck is empty; cannot draw more cards","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"BoardGame-CLI/uno.py","lineNumber":69,"sourceCode":"\n\"\"\"Draw card function that draws a specified number of cards off the top of the deck\nParameters: numCards -> integer\nReturn: cardsDrawn -> list\n\"\"\"\n\n\ndef drawCards(numCards: int) -> List[str]:\n    \"\"\"\n    Draw a number of cards from the top of the global `unoDeck`.\n\n    Raises ValueError if the deck runs out of cards.\n    \"\"\"\n    cardsDrawn: List[str] = []\n    for x in range(numCards):\n        try:\n            cardsDrawn.append(unoDeck.pop(0))\n        except IndexError:\n            raise ValueError(\"The deck is empty; cannot draw more cards\")\n    return cardsDrawn\n\n\n\"\"\"\nPrint formatted list of player's hand\nParameter: player->integer , playerHand->list\nReturn: None\n\"\"\"\n\n\ndef showHand(player: int, playerHand: List[str]) -> None:\n    print(\"Player {}'s Turn\".format(players_name[player]))\n    print(\"Your Hand\")\n    print(\"------------------\")\n    y = 1\n    for card in playerHand:\n        print(\"{}) {}\".format(y, card))\n        y += 1","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/BoardGame-CLI/uno.py#L51-L87","documentation":"Raised by drawCards in the UNO CLI when the deck list runs out while trying to pop the requested number of cards. The code converts the underlying IndexError from unoDeck.pop(0) into a ValueError with an explanatory message.","triggerScenarios":"Calling drawCards(numCards) when len(unoDeck) < numCards, typically near the end of a long game where the draw pile was never replenished from played/discarded cards.","commonSituations":"Long UNO games where the deck isn't recycled; dealing at startup with a deck that was already depleted or mis-shuffled; drawing penalty cards (e.g. after a Draw Four) at the very end of the deck.","solutions":["Before drawing, reshuffle the discard pile back into the deck when it gets low (standard UNO rule)","Check len(unoDeck) >= numCards before calling drawCards and rebuild the deck if not","Catch the ValueError in main and trigger a deck-reshuffle then retry the draw once","Reduce numCards to what remains if the game is ending"],"exampleFix":"// before\ncards = drawCards(unoDeck, 2)\n// after\nif len(unoDeck) < 2:\n    unoDeck = reshuffle_discard(discard_pile)\ncards = drawCards(unoDeck, 2)","handlingStrategy":"fallback","validationCode":"def safe_draw(unoDeck, discard, n):\n    if len(unoDeck) < n:\n        unoDeck.extend(reshuffle(discard))\n    return drawCards(unoDeck, n) if len(unoDeck) >= n else None","typeGuard":null,"tryCatchPattern":"try:\n    cards = drawCards(unoDeck, n)\nexcept ValueError:\n    unoDeck.extend(reshuffle_discard_pile())\n    cards = drawCards(unoDeck, n)","preventionTips":["Recycle the discard pile into the deck when it drops below a threshold (e.g. 10 cards)","Check len(unoDeck) >= requested count before drawing","Cap penalty draws at the remaining deck size"],"tags":["uno","deck-exhausted","card-game","value-error"],"backgroundTag":"resource-pool-exhausted","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}