{"record":{"id":"a2a2cbbedaa572b4","repo":"krahets/hello-algo","slug":"error-a2a2cb","errorCode":null,"errorMessage":"очередь пуста","messagePattern":"очередь пуста","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ru/codes/zig/chapter_stack_and_queue/linkedlist_queue.zig","lineNumber":48,"sourceCode":"        // Деструктор (освобождение памяти)\n        pub fn deinit(self: *Self) void {\n            if (self.mem_arena == null) return;\n            self.mem_arena.?.deinit();\n        }\n\n        // Получение длины очереди\n        pub fn size(self: *Self) usize {\n            return self.que_size;\n        }\n\n        // Проверка, пуста ли очередь\n        pub fn isEmpty(self: *Self) bool {\n            return self.size() == 0;\n        }\n\n        // Доступ к элементу в начале очереди\n        pub fn peek(self: *Self) T {\n            if (self.size() == 0) @panic(\"очередь пуста\");\n            return self.front.?.val;\n        }  \n\n        // Поместить в очередь\n        pub fn push(self: *Self, num: T) !void {\n            // Добавить num после хвостового узла\n            var node = try self.mem_allocator.create(inc.ListNode(T));\n            node.init(num);\n            // Если очередь пуста, сделать так, чтобы и head, и tail указывали на этот узел\n            if (self.front == null) {\n                self.front = node;\n                self.rear = node;\n            // Если очередь не пуста, добавить этот узел после хвостового узла\n            } else {\n                self.rear.?.next = node;\n                self.rear = node;\n            }\n            self.que_size += 1;","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/zig/chapter_stack_and_queue/linkedlist_queue.zig#L30-L66","documentation":"Unrecoverable Zig @panic from peek() on the singly-linked-list queue. The guard is `if (self.size() == 0) @panic(\"очередь пуста\")` executed before `self.front.?.val`; it prevents a null dereference when the queue holds no nodes. The queue returns the front value without removing it, and an empty peek is treated as a caller bug.","triggerScenarios":"Call peek() on a LinkedListQueue that has had zero pushes, or whose front==null because all elements were dequeued. Also hit by helper code that peeks before the first enqueue.","commonSituations":"Polling a queue before a producer has enqueued anything; BFS/level-order traversal that peeks the queue after draining the last node; reporting the queue head in logs/UI without a size check.","solutions":["Check `q.isEmpty()` (or `q.size() > 0`) immediately before peek().","Restructure the consumer loop to dequeue (not peek) until isEmpty, so no peek can run at size 0.","Provide a wrapper that returns ?T for callers that legitimately face an empty queue."],"exampleFix":"// before\nconst head = q.peek();\n// after\nconst head = if (q.isEmpty()) null else q.peek();","handlingStrategy":"validation","validationCode":"// call BEFORE peek()\nif (q.isEmpty()) return null;\nconst head = q.peek();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always check isEmpty()/size() before peek().","Consume with `while (!q.isEmpty())` so peek never runs at size 0.","If empty-peek is legitimate, build a ?T-returning wrapper."],"tags":["zig","queue","peek","data-structure","empty-state"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}