{"record":{"id":"bcd9b8fb68ef51b6","repo":"Textualize/textual","slug":"no-screens-on-stack","errorCode":null,"errorMessage":"No screens on stack","messagePattern":"No screens on stack","errorType":"exception","errorClass":"ScreenStackError","httpStatus":null,"severity":"error","filePath":"src/textual/app.py","lineNumber":1641,"sourceCode":"        \"\"\"The animator object.\"\"\"\n        return self._animator\n\n    @property\n    def screen(self) -> Screen[object]:\n        \"\"\"The current active screen.\n\n        Returns:\n            The currently active (visible) screen.\n\n        Raises:\n            ScreenStackError: If there are no screens on the stack.\n        \"\"\"\n        try:\n            return self._screen_stack[-1]\n        except KeyError:\n            raise UnknownModeError(f\"No known mode {self._current_mode!r}\") from None\n        except IndexError:\n            raise ScreenStackError(\"No screens on stack\") from None\n\n    @property\n    def _background_screens(self) -> list[Screen]:\n        \"\"\"A list of screens that may be visible due to background opacity (top-most first, not including current screen).\"\"\"\n        screens: list[Screen] = []\n        for screen in reversed(self._screen_stack[:-1]):\n            screens.append(screen)\n            if screen.styles.background.a == 1:\n                break\n        background_screens = screens[::-1]\n        return background_screens\n\n    @property\n    def size(self) -> Size:\n        \"\"\"The size of the terminal.\n\n        Returns:\n            Size of the terminal.","sourceCodeStart":1623,"sourceCodeEnd":1659,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/app.py#L1623-L1659","documentation":"ScreenStackError raised by App.screen when the current mode's screen stack is empty (IndexError on _screen_stack[-1]). Every mode should always keep at least one screen; an empty stack means screens were popped without replacement.","triggerScenarios":"Calling pop_screen() on a stack with one screen in a mode where guards were bypassed, or accessing app.screen during teardown after the last screen was removed.","commonSituations":"Exit paths that pop the root screen; race between screen unmount and mode switching.","solutions":["Guard pops: if len(app.screen_stack) > 1: app.pop_screen()","Use app.exit() instead of popping the last screen when ending the app","Prefer switch_screen for replacing rather than push+pop patterns"],"exampleFix":"# before\nif len(self.app.screen_stack) == 1:\n    self.app.pop_screen()  # empties stack\n\n# after\nif len(self.app.screen_stack) == 1:\n    self.app.exit()\nelse:\n    self.app.pop_screen()","handlingStrategy":"validation","validationCode":"def can_pop(app) -> bool:\n    return len(app.screen_stack) > 1","typeGuard":null,"tryCatchPattern":"try:\n    app.pop_screen()\nexcept ScreenStackError:\n    app.exit()","preventionTips":["Guard pop_screen with stack length","Use app.exit() to terminate instead of popping the root screen"],"tags":["screen-stack","textual","state-error"],"backgroundTag":"empty-screen-stack","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}