Skip to content

search, namedqueries: move first/last in an empty buffer - #1867

Merged
pazz merged 1 commit into
mainfrom
search-move-empty
Nov 23, 2026
Merged

pazz merged 1 commit into
mainfrom
search-move-empty

Conversation

@pazz

@pazz pazz commented Nov 22, 2026

Copy link
Copy Markdown
Owner

move first and move last showed an error ("Can't set focus, ListBox is empty") instead of doing nothing in:

  • a search without results;
  • a search with a malformed query (move last also failed with 'NoneType' object has no attribute 'empty');
  • the named queries buffer without any named queries (move first only; move last already checked).

The search buffer now returns early when its list has no focus widget, which urwid documents as None for an empty ListBox since before 2.2.0. The named queries buffer checks self.queries, as its rebuild does. The bug was found in the review of #1865.

Testing

Unit tests in tests/buffers/test_search.py (no results, malformed query) and tests/buffers/test_namedqueries.py (no queries) run the real urwid ListBox; all three fail without the fix. The full suite passes. During development, equivalent end-to-end tests in a pty also failed without the fix and passed with it; they were replaced by the unit tests on review-design's advice.

NEWS: info: "move first" and "move last" no longer fail in an empty search or named queries buffer

Review findings and resolution

review-correctness

  • Nothing to change.
  • After a reversed rebuild, a search emptied by tagging no longer rebuilds on move first until refreshed: left, a rare corner where doing nothing is reasonable.
  • TagListBuffer has the same unguarded focus_first, but an empty tag list cannot be opened, because rebuild divides by the number of tags: left, as a notmuch database in use always has tags.
  • The guards are written differently in the two buffers: left, each matches its buffer's own data.
  • Two end-to-end tests fail under HOME=/nonexistent on the reviewer's machine: an environment effect (a system urwidtrees 1.0.4 is picked up), same on main.

review-design

  • Replace the end-to-end tests with unit tests next to the existing buffer tests: done.
  • TagListBuffer.rebuild raises ZeroDivisionError without tags: left, as a notmuch database in use always has tags.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TR9KjabaVCyHnpqp2kQZHC

"move first" and "move last" raised IndexError ("Can't set focus,
ListBox is empty") in a search without results or with a malformed
query, and "move first" in the named queries buffer without any named
queries. Do nothing there instead, as the named queries buffer already
does for "move last".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TR9KjabaVCyHnpqp2kQZHC
@pazz
pazz merged commit cded4c3 into main Nov 23, 2026
12 checks passed
@pazz
pazz deleted the search-move-empty branch November 23, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant