{"record":{"id":"d8955155d708b579","repo":"krahets/hello-algo","slug":"error-d89551","errorCode":null,"errorMessage":"スタックが空","messagePattern":"スタックが空","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ja/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/ja/codes/javascript/chapter_stack_and_queue/array_stack.js#L13-L49","documentation":"Thrown by the array-based stack's pop when the stack is empty. The guard prevents calling Array.pop semantics on an already-empty internal array and avoids returning undefined. The check uses this.#stack.length === 0 via isEmpty().","triggerScenarios":"Calling pop() on a freshly created stack with no pushes; popping more times than you pushed; popping in a loop without an empty check.","commonSituations":"Bracket/expression matching where input is unbalanced; recursion simulation that over-pops; calling pop without verifying state.","solutions":["Check stack.isEmpty() before pop().","Use while (!stack.isEmpty()) for drain loops.","Return a sentinel (e.g. null/undefined) when empty rather than throwing.","Ensure push/pop are balanced in your algorithm."],"exampleFix":"// before\nconst top = stack.pop();  // throws if empty\n\n// after\nconst top = stack.isEmpty() ? null : stack.pop();","handlingStrategy":"validation","validationCode":"function safePop(stack) {\n  return stack.isEmpty() ? null : stack.pop();\n}","typeGuard":"const isNonEmpty = (s) => typeof s.isEmpty === 'function' && !s.isEmpty();","tryCatchPattern":"try {\n  return stack.pop();\n} catch (e) {\n  if (e instanceof Error && e.message === 'スタックが空') return null;\n  throw e;\n}","preventionTips":["Check isEmpty() before pop().","Keep push/pop balanced in your algorithm.","Return a sentinel when empty."],"tags":["stack","javascript","empty-state","array"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}