{"record":{"id":"397772e7a7f7915e","repo":"krahets/hello-algo","slug":"error-397772","errorCode":null,"errorMessage":"スタックが空です","messagePattern":"スタックが空です","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ja/codes/zig/chapter_stack_and_queue/linkedlist_stack.zig","lineNumber":46,"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.stk_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.stack_top.?.val;\n        }  \n\n        // プッシュ\n        pub fn push(self: *Self, num: T) !void {\n            var node = try self.mem_allocator.create(inc.ListNode(T));\n            node.init(num);\n            node.next = self.stack_top;\n            self.stack_top = node;\n            self.stk_size += 1;\n        } \n\n        // ポップ\n        pub fn pop(self: *Self) T {\n            var num = self.peek();\n            self.stack_top = self.stack_top.?.next;\n            self.stk_size -= 1;\n            return num;","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ja/codes/zig/chapter_stack_and_queue/linkedlist_stack.zig#L28-L64","documentation":"This panic is raised by peek() in a singly-linked-list stack (Japanese localization). It fires when reading the top element while stk_size == 0. The guard prevents a null stack_top dereference. @panic is uncatchable in Zig.","triggerScenarios":"Calling stack.peek() before any push, or after pop() has removed the last element.","commonSituations":"Monotone-stack algorithms reading the top when empty; DFS stack checked at the wrong loop point; porting catchable EmptyStackException code.","solutions":["Guard with stack.isEmpty() before peek().","Loop with while (!stack.isEmpty()) and peek inside.","Verify size() > 0 before any top access.","Use a wrapper returning ?T if recoverable semantics are needed."],"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":["Check stack.isEmpty() before every peek().","Drive consumption with while (!stack.isEmpty()).","@panic is uncatchable in Zig — validation is the only defense."],"tags":["zig","stack","panic","precondition","data-structure","i18n-ja"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}