{"record":{"id":"82b8625f37dbf20e","repo":"krahets/hello-algo","slug":"error-82b862","errorCode":null,"errorMessage":"очередь пуста","messagePattern":"очередь пуста","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"ru/codes/ruby/chapter_stack_and_queue/linkedlist_queue.rb","lineNumber":55,"sourceCode":"      @rear.next = node\n      @rear = node\n    end\n\n    @size += 1\n  end\n\n  ### Извлечение из очереди ###\n  def pop\n    num = peek\n    # Удалить головной узел\n    @front = @front.next\n    @size -= 1\n    num\n  end\n\n  ### Доступ к элементу в начале очереди ###\n  def peek\n    raise IndexError, 'очередь пуста' if is_empty?\n\n    @front.val\n  end\n\n  ### Преобразовать связный список в Array и вернуть ###\n  def to_array\n    queue = []\n    temp = @front\n    while temp\n      queue << temp.val\n      temp = temp.next\n    end\n    queue\n  end\nend\n\n### Driver Code ###\nif __FILE__ == $0","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/ruby/chapter_stack_and_queue/linkedlist_queue.rb#L37-L73","documentation":"Raised by LinkedListQueue#peek (ru) on an empty queue. `pop` delegates to peek (`num = peek`), so this same raise surfaces for both `peek` and `pop` when empty. The guard protects `@front.val` from a nil @front.","triggerScenarios":"Calling `queue.peek` or `queue.pop` on an empty LinkedListQueue — before any push, or after the last element is dequeued. A consumer that overshoots triggers it.","commonSituations":"Consumer faster than producer; dequeuing the last item then dequeuing once more; a driver that peeks before the first push.","solutions":["Guard with `queue.is_empty?` before peek or pop.","Drive consumer loops with `until queue.is_empty?`.","Wrap pop in a helper returning nil on empty for optional semantics."],"exampleFix":"// before\nqueue.pop  # raises 'очередь пуста' when empty\n\n// after\nitem = queue.is_empty? ? nil : queue.pop","handlingStrategy":"validation","validationCode":"item = queue.pop unless queue.is_empty?","typeGuard":"def queue_nonempty?(q) = !q.is_empty?","tryCatchPattern":"begin\n  item = queue.pop  # also covers peek\nrescue IndexError\n  item = nil\nend","preventionTips":["pop routes through peek — guard covers both.","Drive consumer loops with `until queue.is_empty?`.","Linked-list queue has no capacity limit — only the empty precondition raises."],"tags":["ruby","queue","linkedlist","empty-state","index-error"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}