{"record":{"id":"8787689e390903a7","repo":"krahets/hello-algo","slug":"error-878768","errorCode":null,"errorMessage":"очередь пуста","messagePattern":"очередь пуста","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ru/codes/typescript/chapter_stack_and_queue/linkedlist_queue.ts","lineNumber":49,"sourceCode":"    push(num: number): void {\n        // Добавить num после хвостового узла\n        const node = new ListNode(num);\n        // Если очередь пуста, сделать так, чтобы и head, и tail указывали на этот узел\n        if (!this.front) {\n            this.front = node;\n            this.rear = node;\n            // Если очередь не пуста, добавить этот узел после хвостового узла\n        } else {\n            this.rear!.next = node;\n            this.rear = node;\n        }\n        this.queSize++;\n    }\n\n    /* Извлечь из очереди */\n    pop(): number {\n        const num = this.peek();\n        if (!this.front) throw new Error('очередь пуста');\n        // Удалить головной узел\n        this.front = this.front.next;\n        this.queSize--;\n        return num;\n    }\n\n    /* Доступ к элементу в начале очереди */\n    peek(): number {\n        if (this.size === 0) throw new Error('очередь пуста');\n        return this.front!.val;\n    }\n\n    /* Преобразовать связный список в Array и вернуть */\n    toArray(): number[] {\n        let node = this.front;\n        const res = new Array<number>(this.size);\n        for (let i = 0; i < res.length; i++) {\n            res[i] = node!.val;","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/typescript/chapter_stack_and_queue/linkedlist_queue.ts#L31-L67","documentation":"Thrown by pop() on a linked-list queue when this.front is null/undefined. The message ('очередь пуста') guards the head-node reassignment this.front = this.front.next. Note peek() is called first and already throws on an empty queue, so this redundant guard is a secondary defense.","triggerScenarios":"Calling pop() on a queue whose front pointer is null (no elements enqueued or all dequeued); a producer/consumer where the consumer dequeues more than was enqueued.","commonSituations":"BFS where the queue is drained and then popped once more; resetting a queue and forgetting to reset downstream consumers; concurrent/async producers where the consumer races ahead.","solutions":["Check queue.isEmpty() (or queue.size === 0) before pop().","Drive consumption with while (!queue.isEmpty()).","Catch the error when an empty dequeue is a recoverable signal.","Ensure enqueue calls precede dequeue calls in the control flow."],"exampleFix":"// before\nconst x = queue.pop(); // throws when front is null\n\n// after\nconst x = queue.isEmpty() ? null : queue.pop();","handlingStrategy":"validation","validationCode":"if (!queue.isEmpty()) {\n    const val = queue.pop();\n}","typeGuard":null,"tryCatchPattern":"try {\n    const val = queue.pop();\n} catch (e) {\n    if (e instanceof Error && e.message === 'очередь пуста') {\n        // queue empty; handle gracefully\n    } else throw e;\n}","preventionTips":["Check queue.size === 0 before pop().","Ensure enqueues precede dequeues in the control flow.","Use while (!queue.isEmpty()) for full drains."],"tags":["queue","typescript","linked-list","empty-state","validation"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}