[RFC PATCH 13/13] review_tui: guard against unmounted diff-viewer In certain asynchronous contexts or during rapid UI transitions, _show_content may be invoked before the diff-viewer widget has been fully mounted in the DOM. This is particularly reproducible in headless test environments and on platforms with slower console I/O initialization.

Adrian Neftali Sanchez <[email protected]>
Newsgroups org.kernel.linux.tools
Message-ID <[email protected]>
Add a defensive try-except block to catch NoMatches when querying for
'#diff-viewer'. If the widget is not yet available, log a debug message
and return early to prevent an application crash.

Signed-off-by: Adrian Neftali Sanchez <[email protected]>
---
 src/b4/review_tui/_review_app.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/b4/review_tui/_review_app.py b/src/b4/review_tui/_review_app.py
index 8786fbb..e6d6e4e 100644
--- a/src/b4/review_tui/_review_app.py
+++ b/src/b4/review_tui/_review_app.py
@@ -18,6 +18,7 @@ from rich.text import Text
 from textual.app import App, ComposeResult
 from textual.binding import Binding
 from textual.containers import Horizontal, Vertical
+from textual.css.query import NoMatches
 from textual.events import Click
 from textual.widgets import Label, ListItem, ListView, RichLog, Static
 
@@ -458,7 +459,12 @@ class ReviewApp(CheckRunnerMixin, App[None]):
         total = len(self._commit_shas)
         if display_idx < 0 or display_idx > total:
             return
-        viewer = self.query_one('#diff-viewer', RichLog)
+        # Defensive: widget may not be mounted yet in headless/async tests
+        try:
+            viewer = self.query_one('#diff-viewer', RichLog)
+        except NoMatches:
+            self.log.debug("diff-viewer not ready for patch %s", display_idx)
+            return
         viewer.clear()
         self._comment_positions = []
         self._followup_positions = {}
-- 
2.45.0.windows.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.