{"record":{"id":"9622560dc97a5f2c","repo":"krahets/hello-algo","slug":"error-962256","errorCode":null,"errorMessage":"キューが空です","messagePattern":"キューが空です","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ja/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            // 先頭ポインタを1つ後ろへ進め、末尾を越えたら配列先頭に戻す\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/ja/codes/zig/chapter_stack_and_queue/array_queue.zig#L59-L95","documentation":"This panic is raised by peek() in an array-backed circular queue (Japanese localization). It fires when reading the front element while isEmpty() is true. The array queue uses front/size pointers over a fixed-capacity ring buffer; peeking with zero elements has no valid slot. pop() calls peek() internally, so pop-on-empty also surfaces here. @panic is uncatchable.","triggerScenarios":"Calling queue.peek() or queue.pop() on an empty queue — i.e., capacity allocated but queSize == 0, or after draining all enqueued items.","commonSituations":"Ring-buffer producer/consumer where the consumer polls faster than the producer; calling pop() in a for-loop bound by capacity rather than by size(); forgetting that pop() delegates to peek().","solutions":["Check queue.isEmpty() before peek() or pop().","Drive consumption with while (queue.size() > 0).","Decouple the consumer so it only pops when size() > 0.","If pop() must be safe, wrap it: if (!isEmpty()) pop();"],"exampleFix":"// before\nvar v = queue.pop(); // internally peeks → @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() calls peek() internally — guarding peek is not enough; guard pop too.","Bound consumer loops by queue.size(), not by capacity.","Treat @panic as a hard abort; there is no recovery path."],"tags":["zig","queue","circular-buffer","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"}