{"record":{"id":"dafcde7f4435f282","repo":"krahets/hello-algo","slug":"error-dafcde","errorCode":null,"errorMessage":"стек пуст","messagePattern":"стек пуст","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ru/codes/zig/chapter_stack_and_queue/array_stack.zig","lineNumber":40,"sourceCode":"        // Деструктор (освобождение памяти)\n        pub fn deinit(self: *Self) void {\n            if (self.stack == null) return;\n            self.stack.?.deinit();\n        }\n\n        // Получение длины стека\n        pub fn size(self: *Self) usize {\n            return self.stack.?.items.len;\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.isEmpty()) @panic(\"стек пуст\");\n            return self.stack.?.items[self.size() - 1];\n        }  \n\n        // Поместить в стек\n        pub fn push(self: *Self, num: T) !void {\n            try self.stack.?.append(num);\n        } \n\n        // Извлечь из стека\n        pub fn pop(self: *Self) T {\n            var num = self.stack.?.pop();\n            return num;\n        } \n\n        // Вернуть ArrayList\n        pub fn toList(self: *Self) std.ArrayList(T) {\n            return self.stack.?;\n        }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/zig/chapter_stack_and_queue/array_stack.zig#L22-L58","documentation":"This panic is raised by peek() in an array-backed stack using std.ArrayList (Russian localization). It fires when reading items[size-1] while empty — the guard prevents both a meaningless read and an unsigned underflow of the index. Note pop() here uses ArrayList.pop directly (not peek), so this panic is specific to peek(). @panic is uncatchable.","triggerScenarios":"Calling stack.peek() when stack.?.items.len == 0; i.e., before any push or after the last pop.","commonSituations":"Empty operator-stack top check; inspecting the top before initialization; peeking once more after a drain loop.","solutions":["Guard with stack.isEmpty() before peek().","Loop with while (!stack.isEmpty()) and peek inside.","Cache size() and only peek when > 0.","Note pop() is also unguarded on this impl — check before popping too."],"exampleFix":"// before\nvar top = stack.peek(); // @panics when empty\n\n// after\nif (stack.isEmpty()) return;\nvar top = stack.peek();","handlingStrategy":"validation","validationCode":"// Validate non-empty before reading the top\nif (!stack.isEmpty()) {\n    var top = stack.peek();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["pop() here does not call peek(), but is itself unguarded — check before popping too.","Use while (!stack.isEmpty()) and peek inside.","@panic is uncatchable in Zig — preconditions are the only defense."],"tags":["zig","stack","array-list","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"}