{"record":{"id":"10c8a2634356683d","repo":"TheAlgorithms/Python","slug":"queue-is-empty","errorCode":null,"errorMessage":"Queue is empty","messagePattern":"Queue is empty","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"data_structures/queues/queue_by_list.py","lineNumber":95,"sourceCode":"        >>> queue.get()\n        10\n        >>> queue.put(40)\n        >>> queue.get()\n        20\n        >>> queue.get()\n        30\n        >>> len(queue)\n        1\n        >>> queue.get()\n        40\n        >>> queue.get()\n        Traceback (most recent call last):\n            ...\n        IndexError: Queue is empty\n        \"\"\"\n\n        if not self.entries:\n            raise IndexError(\"Queue is empty\")\n        return self.entries.pop(0)\n\n    def rotate(self, rotation: int) -> None:\n        \"\"\"Rotate the items of the Queue `rotation` times\n\n        >>> queue = QueueByList([10, 20, 30, 40])\n        >>> queue\n        Queue((10, 20, 30, 40))\n        >>> queue.rotate(1)\n        >>> queue\n        Queue((20, 30, 40, 10))\n        >>> queue.rotate(2)\n        >>> queue\n        Queue((40, 10, 20, 30))\n        \"\"\"\n\n        put = self.entries.append\n        get = self.entries.pop","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/data_structures/queues/queue_by_list.py#L77-L113","documentation":"Raised by QueueByList.get() (data_structures/queues/queue_by_list.py:95) when self.entries is empty. The underlying store is a plain list and get() returns self.entries.pop(0), so the guard prevents popping from an empty list and substitutes a clear IndexError message. Length is available via len(queue) and the repr is Queue((...)).","triggerScenarios":"Calling get() on QueueByList() with no constructor argument, or calling get() more times than entries exist (the doctest shows get() after draining 10,20,30,40).","commonSituations":"Reusing a queue across iterations without re-filling, consumer loops that assume the producer already ran, and off-by-one counts after rotate() (rotate does not consume items, so mismatches usually come from elsewhere).","solutions":["Pre-check with `if queue:` or len(queue) before get()","Wrap drain loops in `while len(queue): queue.get()`","Catch IndexError if you intentionally run-until-empty"],"exampleFix":"// before\nitem = queue.get()\n\n# after\nitem = queue.get() if len(queue) else None","handlingStrategy":"validation","validationCode":"if not queue.entries:  # or: if not len(queue)\n    return None\nitem = queue.get()","typeGuard":null,"tryCatchPattern":"try:\n    item = queue.get()\nexcept IndexError as e:\n    if str(e) != 'Queue is empty':\n        raise\n    item = None","preventionTips":["Re-fill the queue between processing rounds","len(queue) is O(1); use it as the loop condition"],"tags":["queue","data-structures","index-error","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}