{"record":{"id":"a087fdb5efb573b9","repo":"krahets/hello-algo","slug":"error-a087fd","errorCode":null,"errorMessage":"очередь пуста","messagePattern":"очередь пуста","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ru/codes/javascript/chapter_stack_and_queue/linkedlist_queue.js","lineNumber":57,"sourceCode":"        } else {\n            this.#rear.next = node;\n            this.#rear = node;\n        }\n        this.#queSize++;\n    }\n\n    /* Извлечь из очереди */\n    pop() {\n        const num = this.peek();\n        // Удалить головной узел\n        this.#front = this.#front.next;\n        this.#queSize--;\n        return num;\n    }\n\n    /* Доступ к элементу в начале очереди */\n    peek() {\n        if (this.size === 0) throw new Error('очередь пуста');\n        return this.#front.val;\n    }\n\n    /* Преобразовать связный список в Array и вернуть */\n    toArray() {\n        let node = this.#front;\n        const res = new Array(this.size);\n        for (let i = 0; i < res.length; i++) {\n            res[i] = node.val;\n            node = node.next;\n        }\n        return res;\n    }\n}\n\n/* Driver Code */\n/* Инициализация очереди */\nconst queue = new LinkedListQueue();","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/javascript/chapter_stack_and_queue/linkedlist_queue.js#L39-L75","documentation":"Thrown by LinkedListQueue.peek (JS) with message 'очередь пуста' when the queue holds zero nodes. pop() calls peek() first and so propagates the throw on an empty dequeue.","triggerScenarios":"Calling peek() or pop() when this.size === 0 (no nodes in the linked list).","commonSituations":"BFS/level-order traversal draining the queue; over-dequeuing relative to enqueue count; consumer faster than producer.","solutions":["Gate peek/pop on this.size === 0 check via the queue's size accessor.","Drain with a captured count: for (let n = q.size; n > 0; n--) q.pop().","Return null from a wrapper when empty instead of propagating the throw."],"exampleFix":"// before\nwhile (q.size >= 0) { q.pop(); } // last iteration throws\n\n// after\nwhile (q.size > 0) { const v = q.pop(); }","handlingStrategy":"validation","validationCode":"while (q.size > 0) { const v = q.pop(); process(v); }","typeGuard":null,"tryCatchPattern":"try { q.pop(); } catch (e) { if (e.message !== 'очередь пуста') throw e; }","preventionTips":["Drain with while (q.size > 0), not >= 0.","Capture size once for fixed-count draining loops.","For BFS, expand the frontier only while the queue is non-empty."],"tags":["queue","linked-list","javascript","precondition","empty-state","hello-algo"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}