{"record":{"id":"b4e974f616f10a64","repo":"Textualize/textual","slug":"no-known-mode-self-current-mode-r","errorCode":null,"errorMessage":"No known mode {self._current_mode!r}","messagePattern":"No known mode (.+?)","errorType":"exception","errorClass":"UnknownModeError","httpStatus":null,"severity":"error","filePath":"src/textual/app.py","lineNumber":1639,"sourceCode":"    @property\n    def animator(self) -> Animator:\n        \"\"\"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","sourceCodeStart":1621,"sourceCodeEnd":1657,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/app.py#L1621-L1657","documentation":"UnknownModeError raised by App.screen when the current mode name has no entry in _screen_stacks. This usually indicates internal state corruption: the active mode's stack was removed or never initialized.","triggerScenarios":"Accessing app.screen after remove_mode deleted the stack of the (still current) mode, or during early startup before the default stack exists.","commonSituations":"Calling remove_mode on the active mode from a worker, race between mode teardown and UI access.","solutions":["Avoid removing the active mode; switch_mode away before remove_mode","Access app.screen only after on_mount has completed","If it persists, reproduce with a minimal app and report — often an internal invariant break"],"exampleFix":"# before\napp.remove_mode(\"editor\")  # while editor is current\n\n# after\nawait app.switch_mode(\"main\")\nawait app.remove_mode(\"editor\")","handlingStrategy":"try-catch","validationCode":"if app._current_mode not in app._screen_stacks:\n    await app.switch_mode('_default')  # recover","typeGuard":null,"tryCatchPattern":"try:\n    s = app.screen\nexcept UnknownModeError:\n    await app.switch_mode('main')\n    s = app.screen","preventionTips":["Never remove the active mode","Avoid touching app.screen before on_mount completes"],"tags":["modes","internal-state","textual"],"backgroundTag":"unknown-mode-requested","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}