{"record":{"id":"cf9e5db1b9cdc0e7","repo":"krahets/hello-algo","slug":"error-cf9e5d","errorCode":null,"errorMessage":"стек пуст","messagePattern":"стек пуст","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ru/codes/javascript/chapter_stack_and_queue/array_stack.js","lineNumber":31,"sourceCode":"\n    /* Получение длины стека */\n    get size() {\n        return this.#stack.length;\n    }\n\n    /* Проверка, пуст ли стек */\n    isEmpty() {\n        return this.#stack.length === 0;\n    }\n\n    /* Поместить в стек */\n    push(num) {\n        this.#stack.push(num);\n    }\n\n    /* Извлечь из стека */\n    pop() {\n        if (this.isEmpty()) throw new Error('стек пуст');\n        return this.#stack.pop();\n    }\n\n    /* Доступ к верхнему элементу стека */\n    top() {\n        if (this.isEmpty()) throw new Error('стек пуст');\n        return this.#stack[this.#stack.length - 1];\n    }\n\n    /* Вернуть Array */\n    toArray() {\n        return this.#stack;\n    }\n}\n\n/* Driver Code */\n/* Инициализация стека */\nconst stack = new ArrayStack();","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/javascript/chapter_stack_and_queue/array_stack.js#L13-L49","documentation":"Thrown by ArrayStack.pop (JS, array_stack.js) with message 'стек пуст' ('stack is empty') when popping from an empty stack. Backed by a plain JS array, the guard prevents relying on Array.pop's silent undefined return.","triggerScenarios":"Calling pop() when #stack.length === 0 (isEmpty() is true).","commonSituations":"Unbalanced push/pop pairs; DFS/recursion-simulation that over-pops; expression-evaluation (e.g., bracket matching) hitting a close with nothing open.","solutions":["Check isEmpty() before pop: if (!stack.isEmpty()) stack.pop().","In bracket/paren matching, treat empty-on-close as a mismatch rather than letting it throw.","Return a sentinel when empty if your algorithm tolerates it."],"exampleFix":"// before\nwhile (stack.size() > 0) doX(stack.pop());\nstack.pop(); // throws if size was miscounted\n\n// after\nwhile (!stack.isEmpty()) doX(stack.pop());","handlingStrategy":"validation","validationCode":"if (!stack.isEmpty()) { const v = stack.pop(); }","typeGuard":null,"tryCatchPattern":"try { stack.pop(); } catch (e) { if (e.message !== 'стек пуст') throw e; }","preventionTips":["Always check isEmpty() before pop.","In bracket matching, treat empty-on-close as a mismatch, not an exception.","Maintain balanced push/pop pairs in expression evaluation."],"tags":["stack","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"}