{"record":{"id":"7fe58311f5f88190","repo":"krahets/hello-algo","slug":"error-7fe583","errorCode":null,"errorMessage":"очередь пуста","messagePattern":"очередь пуста","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ru/codes/zig/chapter_stack_and_queue/array_queue.zig","lineNumber":77,"sourceCode":"            // С помощью операции взятия по модулю вернуть rear к началу после выхода за конец массива\n            var rear = (self.front + self.queSize) % self.capacity();\n            // Добавить num после хвостового узла\n            self.nums[rear] = num;\n            self.queSize += 1;\n        } \n\n        // Извлечь из очереди\n        pub fn pop(self: *Self) T {\n            var num = self.peek();\n            // Указатель head сдвигается на одну позицию назад; если он выходит за конец, то возвращается в начало массива\n            self.front = (self.front + 1) % self.capacity();\n            self.queSize -= 1;\n            return num;\n        } \n\n        // Доступ к элементу в начале очереди\n        pub fn peek(self: *Self) T {\n            if (self.isEmpty()) @panic(\"очередь пуста\");\n            return self.nums[self.front];\n        } \n\n        // Вернуть массив\n        pub fn toArray(self: *Self) ![]T {\n            // Преобразовывать только элементы списка в пределах фактической длины\n            var res = try self.mem_allocator.alloc(T, self.size());\n            @memset(res, @as(T, 0));\n            var i: usize = 0;\n            var j: usize = self.front;\n            while (i < self.size()) : ({ i += 1; j += 1; }) {\n                res[i] = self.nums[j % self.capacity()];\n            }\n            return res;\n        }\n    };\n}\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/zig/chapter_stack_and_queue/array_queue.zig#L59-L95","documentation":"This panic is raised by peek() in an array-backed circular queue (Russian localization). It fires when reading nums[front] while isEmpty() is true. pop() calls peek() internally, so pop-on-empty surfaces here too. The ring buffer has no valid element to return when queSize == 0. @panic is uncatchable.","triggerScenarios":"Calling queue.peek() or queue.pop() on an empty queue (capacity allocated, queSize 0), or after draining all items.","commonSituations":"Consumer polling faster than producer in a ring buffer; loop bounded by capacity instead of size(); forgetting pop() delegates to peek().","solutions":["Check queue.isEmpty() before peek() or pop().","Drive consumption with while (queue.size() > 0).","Only pop when size() confirms an element exists.","Wrap pop: if (!queue.isEmpty()) _ = queue.pop();"],"exampleFix":"// before\nvar v = queue.pop(); // peeks internally → @panics when empty\n\n// after\nif (queue.isEmpty()) return;\nvar v = queue.pop();","handlingStrategy":"validation","validationCode":"// Validate non-empty before peek/pop\nif (!queue.isEmpty()) {\n    var v = queue.peek();\n    _ = queue.pop();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["pop() delegates to peek() — guard both.","Bound consumer loops by queue.size(), not capacity.","Treat @panic as a hard abort with no recovery."],"tags":["zig","queue","circular-buffer","panic","precondition","data-structure","i18n-ru"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}