{"record":{"id":"2fd167aba34e0f2c","repo":"krahets/hello-algo","slug":"error-2fd167","errorCode":null,"errorMessage":"двусторонняя очередь пуста","messagePattern":"двусторонняя очередь пуста","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ru/codes/zig/chapter_stack_and_queue/linkedlist_deque.zig","lineNumber":100,"sourceCode":"                node.prev = self.rear;\n                self.rear = node;   // Обновить хвостовой узел\n            }\n            self.que_size += 1;      // Обновить длину очереди\n        } \n\n        // Добавление в голову очереди\n        pub fn pushFirst(self: *Self, num: T) !void {\n            try self.push(num, true);\n        } \n\n        // Добавление в хвост очереди\n        pub fn pushLast(self: *Self, num: T) !void {\n            try self.push(num, false);\n        } \n        \n        // Операция извлечения из очереди\n        pub fn pop(self: *Self, is_front: bool) T {\n            if (self.isEmpty()) @panic(\"двусторонняя очередь пуста\");\n            var val: T = undefined;\n            // Операция извлечения из головы очереди\n            if (is_front) {\n                val = self.front.?.val;     // Временно сохранить значение головного узла\n                // Удалить головной узел\n                var fNext = self.front.?.next;\n                if (fNext != null) {\n                    fNext.?.prev = null;\n                    self.front.?.next = null;\n                }\n                self.front = fNext;         // Обновить головной узел\n            // Операция извлечения из хвоста очереди\n            } else {\n                val = self.rear.?.val;      // Временно сохранить значение хвостового узла\n                // Удалить хвостовой узел\n                var rPrev = self.rear.?.prev;\n                if (rPrev != null) {\n                    rPrev.?.next = null;","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/zig/chapter_stack_and_queue/linkedlist_deque.zig#L82-L118","documentation":"This is an unrecoverable Zig @panic raised by the linked-list deque's pop() when the deque is empty. The library uses @panic (not a returned error) because popping from an empty deque is a logic error in the caller, not an expected runtime condition. It fires inside pop(is_front) after isEmpty() returns true, i.e. before any node access, so it prevents the subsequent self.front.?.val unwrap from dereferencing null.","triggerScenarios":"Call popFirst() or popLast() (which delegate to pop(true)/pop(false)) on a LinkedListDeque that has zero elements, or that you already drained. Any second pop on a deque containing exactly one element before pushing again will also trip it, since after the first pop the size reaches 0.","commonSituations":"Draining a deque in a loop and then popping one more element; writing a producer/consumer where the consumer outruns the producer; calling pop() without first consulting size() or isEmpty(); reusing a deque instance after a clear()/drain operation.","solutions":["Guard every popFirst()/popLast() call with a preceding `if (!dq.isEmpty())` check, or read dq.size() first.","Track the logical element count in the loop condition so the loop stops when size() reaches 0 instead of issuing an extra pop.","If you need recoverable semantics, wrap the deque and convert the empty case into a returned error or an optional value rather than letting @panic fire."],"exampleFix":"// before\nvar v = dq.popFirst();\n// after\nif (dq.isEmpty()) return null;\nvar v = dq.popFirst();","handlingStrategy":"validation","validationCode":"// call BEFORE popFirst()/popLast()\nif (dq.isEmpty()) return;   // or return null / an error\nconst v = dq.popFirst();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always read size() or isEmpty() before any pop on a deque.","Drive drain loops with `while (!dq.isEmpty())` so the loop cannot issue an extra pop.","Keep producer/consumer in sync so the consumer never leads by more pops than pushes."],"tags":["zig","deque","data-structure","panic","empty-state"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}