{"record":{"id":"4a7862dd926f201a","repo":"krahets/hello-algo","slug":"error-4a7862","errorCode":null,"errorMessage":"双向队列为空","messagePattern":"双向队列为空","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"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/codes/zig/chapter_stack_and_queue/linkedlist_deque.zig#L82-L118","documentation":"@panic in pop(is_front) of the Zig LinkedListDeque when the deque is empty. pop() must dereference front or rear to retrieve a value, which is invalid when the deque holds no nodes, so it aborts with '双向队列为空' (deque is empty). Both popFirst() and popLast() delegate to pop(), so they share this panic. @panic in Zig is unrecoverable and terminates the process.","triggerScenarios":"Calling popFirst()/popLast() on a freshly initialized deque with no pushes; popping after draining all elements; a work-stealing loop that pops more items than were pushed.","commonSituations":"Task deques where consumers outpace producers; replaying a pop sequence longer than the push sequence; assuming popFirst is independently safe because popLast already emptied the deque.","solutions":["Call isEmpty() before popFirst()/popLast(); never pop when empty.","Loop with `while (!deque.isEmpty())` for full drains.","Track the live count externally and gate pops on it.","Provide a safe wrapper returning ?T / an error for empty pops."],"exampleFix":"// before: @panics '双向队列为空' on empty deque\nconst v = deque.popFirst();\n\n// after\nif (!deque.isEmpty()) {\n    const v = deque.popFirst();\n}","handlingStrategy":"validation","validationCode":"// Covers popFirst()/popLast() — both delegate to pop().\nif (!deque.isEmpty()) {\n    const v = deque.popFirst();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Zig @panic aborts — call isEmpty() before popFirst()/popLast().","Both pop helpers delegate to pop(), so they share the empty-deque panic.","Track the live count externally and gate pops on it in producer/consumer code."],"tags":["zig","deque","empty-state","pop","validation"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}