{"record":{"id":"5431d07961d07c8a","repo":"krahets/hello-algo","slug":"error-5431d0","errorCode":null,"errorMessage":"стек пуст","messagePattern":"стек пуст","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ru/codes/typescript/chapter_stack_and_queue/array_stack.ts","lineNumber":31,"sourceCode":"\n    /* Получение длины стека */\n    get size(): number {\n        return this.stack.length;\n    }\n\n    /* Проверка, пуст ли стек */\n    isEmpty(): boolean {\n        return this.stack.length === 0;\n    }\n\n    /* Поместить в стек */\n    push(num: number): void {\n        this.stack.push(num);\n    }\n\n    /* Извлечь из стека */\n    pop(): number | undefined {\n        if (this.isEmpty()) throw new Error('стек пуст');\n        return this.stack.pop();\n    }\n\n    /* Доступ к верхнему элементу стека */\n    top(): number | undefined {\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/typescript/chapter_stack_and_queue/array_stack.ts#L13-L49","documentation":"Thrown by pop() on an array-backed stack when isEmpty() is true. The message ('стек пуст', Russian for 'stack is empty') guards the underlying Array.pop so the method can return a concrete number instead of undefined.","triggerScenarios":"Calling pop() more times than push() was called; popping a freshly constructed empty stack; an unbalanced push/pop sequence in expression evaluation or backtracking.","commonSituations":"DFS/recursion simulation that pops past the root; bracket-matching or undo logic that under-counts the stack depth; popping inside a loop without a size bound.","solutions":["Check stack.isEmpty() before pop().","Use while (!stack.isEmpty()) for full drains, or bound pops by stack.size().","Catch the error when an empty pop is a recoverable condition.","Audit push/pop pairing in the algorithm to ensure balance."],"exampleFix":"// before\nconst top = stack.pop(); // throws if empty\n\n// after\nconst top = stack.isEmpty() ? undefined : stack.pop();","handlingStrategy":"validation","validationCode":"if (!stack.isEmpty()) {\n    const top = stack.pop();\n}","typeGuard":null,"tryCatchPattern":"try {\n    const top = stack.pop();\n} catch (e) {\n    if (e instanceof Error && e.message === 'стек пуст') {\n        // empty stack; handle gracefully\n    } else throw e;\n}","preventionTips":["Check isEmpty() before pop().","Audit push/pop pairing in evaluators and DFS code.","Bound drain loops by stack.size() or use while (!isEmpty())."],"tags":["stack","typescript","empty-state","array-backed","validation"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}