{"record":{"id":"8d6108696c456fc8","repo":"TheAlgorithms/Python","slug":"queue-is-full","errorCode":null,"errorMessage":"QUEUE IS FULL","messagePattern":"QUEUE IS FULL","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"data_structures/queues/circular_queue.py","lineNumber":74,"sourceCode":"        >>> cq.enqueue(\"A\")  # doctest: +ELLIPSIS\n        <data_structures.queues.circular_queue.CircularQueue object at ...>\n        >>> (cq.size, cq.first())\n        (1, 'A')\n        >>> cq.enqueue(\"B\")  # doctest: +ELLIPSIS\n        <data_structures.queues.circular_queue.CircularQueue object at ...>\n        >>> cq.array\n        ['A', 'B', None, None, None]\n        >>> (cq.size, cq.first())\n        (2, 'A')\n        >>> cq.enqueue(\"C\").enqueue(\"D\").enqueue(\"E\")  # doctest: +ELLIPSIS\n        <data_structures.queues.circular_queue.CircularQueue object at ...>\n        >>> cq.enqueue(\"F\")\n        Traceback (most recent call last):\n           ...\n        Exception: QUEUE IS FULL\n        \"\"\"\n        if self.size >= self.n:\n            raise Exception(\"QUEUE IS FULL\")\n\n        self.array[self.rear] = data\n        self.rear = (self.rear + 1) % self.n\n        self.size += 1\n        return self\n\n    def dequeue(self):\n        \"\"\"\n        This function removes an element from the queue using on self.front value as an\n        index and returns it\n\n        >>> cq = CircularQueue(5)\n        >>> cq.dequeue()\n        Traceback (most recent call last):\n           ...\n        Exception: UNDERFLOW\n        >>> cq.enqueue(\"A\").enqueue(\"B\").dequeue()\n        'A'","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/data_structures/queues/circular_queue.py#L56-L92","documentation":"CircularQueue.enqueue raises a generic Exception('QUEUE IS FULL') when self.size >= self.n (fixed capacity given at construction). The ring buffer deliberately keeps all n slots usable via modular front/rear indices; the exception is the overflow signal for a non-growing structure.","triggerScenarios":"Enqueueing the (n+1)-th item without an intervening dequeue: cq = CircularQueue(5); five enqueues are fine, the sixth raises. Also enqueueing into a queue constructed with a too-small capacity.","commonSituations":"Producer faster than consumer (bounded-queue backpressure not implemented); capacity taken from config or len(data) minus one by mistake; porting code from queue.Queue which blocks instead of raising.","solutions":["Check cq.size < cq.n (or compare size to capacity) before enqueueing.","Dequeue before enqueue when full, or block/backpressure the producer.","Size the queue for peak burst depth at construction time."],"exampleFix":"# before\ncq.enqueue(item)  # Exception: QUEUE IS FULL\n# after\nif cq.size < cq.n:\n    cq.enqueue(item)\nelse:\n    cq.dequeue()\n    cq.enqueue(item)","handlingStrategy":"validation","validationCode":"def enqueue_safe(cq, item, drop_oldest=False):\n    if cq.size >= cq.n:\n        if not drop_oldest:\n            return False\n        cq.dequeue()\n    cq.enqueue(item)\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    cq.enqueue(item)\nexcept Exception as e:\n    if 'QUEUE IS FULL' not in str(e):\n        raise\n    cq.dequeue()\n    cq.enqueue(item)","preventionTips":["Compare cq.size to cq.n before every enqueue.","Size capacity to worst-case burst length at construction.","Decide on overflow policy (drop-oldest vs backpressure) up front."],"tags":["queue","overflow","circular-buffer","capacity"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}