{"record":{"id":"b4a372b4b6b98aab","repo":"geekcomputers/Python","slug":"not-enough-chips","errorCode":null,"errorMessage":"Not enough chips","messagePattern":"Not enough chips","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"BlackJack_game/blackjack_simulate.py","lineNumber":176,"sourceCode":"\n    def double_bet(self):\n        if self.can_double():\n            self._bet_amount *= 2\n            self.is_double = True\n        else:\n            over_tips = \"Not enough chips || \"\n            cannot_double = \"CAN'T DO DOUBLE\"\n            raise ValueError(Chips.get_tips(over_tips + cannot_double))\n\n    @property\n    def insurance(self):\n        return self._insurance\n\n    @insurance.setter\n    def insurance(self, value):\n        if self.amount - value < 0:\n            over_tips = \"Not enough chips\"\n            raise ValueError(Chips.get_tips(over_tips))\n        self._insurance = value\n        self.is_insurance = True\n\n    def current_amount(self):\n        return self.amount - self.bet_amount - self.insurance\n\n    def reset_chip(self):\n        self._bet_amount = 0\n        self._insurance = 0\n        self.is_double = False\n        self.is_insurance = False\n\n    def can_double(self):\n        return self.current_amount() - self.bet_amount >= 0\n\n\nclass User:\n    def __init__(self, name, role, chips_amount=None, color=\"END\"):","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/BlackJack_game/blackjack_simulate.py#L158-L194","documentation":"Raised by the Chips.insurance setter in the blackjack simulator when setting an insurance amount that would push the player's total committed chips (bet + insurance) below zero. It is a domain-rules error enforcing that a player cannot insure more chips than they currently hold. The message is formatted via Chips.get_tips.","triggerScenarios":"Calling player.chips.insurance = value where value > chips.amount (e.g. setting insurance 50 when amount is 40), or stacking insurance on top of an existing bet so amount - value < 0.","commonSituations":"Game-loop code that computes insurance as a fraction of the bet without clamping to available chips; tests that construct Chips with a small amount then assign a large insurance.","solutions":["Clamp the insurance value to the available chips before assigning: insurance = min(requested, chips.amount - chips.bet_amount)","Ensure the bet was deducted/checked before offering insurance","In the UI/game loop, disable the insurance option when chips.amount <= 0","Wrap the assignment in try/except ValueError and re-prompt the player"],"exampleFix":"// before\nchips.insurance = requested_insurance\n// after\nmax_ins = chips.amount - chips.bet_amount\nchips.insurance = min(requested_insurance, max_ins)","handlingStrategy":"validation","validationCode":"available = chips.amount - chips.bet_amount\nif requested_insurance > available:\n    requested_insurance = max(available, 0)\nchips.insurance = requested_insurance","typeGuard":null,"tryCatchPattern":"try:\n    chips.insurance = value\nexcept ValueError:\n    # re-prompt player or skip insurance\n    pass","preventionTips":["Compute available chips as amount - bet_amount before offering insurance","Clamp user inputs to available chips in the UI layer","Disable insurance when amount <= 0"],"tags":["blackjack","chips","insurance","value-error","game-logic"],"backgroundTag":"insufficient-funds","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}