Skip to content

Menus: a check that raises no longer leaves later items stale (#354) - #379

Merged
danjboyd merged 1 commit into
mainfrom
fix/354-menu-validation
Nov 18, 2026
Merged

danjboyd merged 1 commit into
mainfrom
fix/354-menu-validation

Conversation

@danjboyd

Copy link
Copy Markdown
Owner

Fixes #354. This is the 0.4.0 fix Dan chose in #8513.

What happened

GNUstep checks a whole menu inside one exception handler (-[NSMenu update], NSMenu.m:1064–1082 at gui-0_32_0). If one -validateMenuItem: raised, the pass stopped there, and every later item kept whatever state it had before.

Source reading points to Paste as New Image's clipboard check as the likely trigger. -clipboardHasImage goes through [NSPasteboard generalPasteboard], which is a round trip to GNUstep's pasteboard server. When that server doesn't answer, the call raises NSPasteboardCommunicationException.

The screenshot in #354 fits a pass that stopped at Paste as New Image:

  • Copy, earlier in the menu, is enabled;
  • Paste as New Image, Copy Text and Redact Emails and Phone Numbers are grey, though Copy Text and Redact would have been enabled;
  • Preferences is enabled.

A complete pass can't produce that combination. The trace is in the #354 comments.

The change

  • -validateMenuItem: now wraps its checks, which move unchanged into -validateMenuItemUnguarded:, in @try/@catch.
  • On an exception it logs the action and the exception to the app log and returns NO for that item only.
  • The rest of the menu is still checked, and the next pass checks that item again.
  • NO is the safe answer: an always-available item ends at the final return YES and has no check that can raise. Only an item whose check failed reaches the @catch.
  • This is shared code (AppDelegate.m), not Windows-only, so it applies on every platform.

Tests

MenuValidationExceptionProbeTests (new, headless):

  • a check that raises disables its own item without raising;
  • the item after a raising check is still checked and enabled;
  • GNUstep only: libs-gui stops a menu pass at an unguarded raise. This test documents the behaviour the fix guards against.

Results on Windows (MSYS2 CLANG64):

  • On this branch (c7484da, tree 84d3e125): 3/3 passed.
  • With the guard removed, the first two fail as expected.
  • Cherry-picked onto the 0.5 print head a6c0620, it applies cleanly (tree cff86d7b). There, 49/49 passed: 3 from this class, plus PrintLayout 34, PrintOptions 7 and WindowsPrintSelection 5.

The Mac and Linux suites need re-running on this change, because it's in shared code.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AEr1tY2QmxWFSoDkDHs2DC

GNUstep checks a whole menu inside one exception handler (-[NSMenu update]).
When one -validateMenuItem: raised, for example when Paste as New Image asked a
pasteboard server that didn't answer, the pass stopped there. Every later item
kept the state it had before, so Copy Text and Redact Emails and Phone Numbers
showed disabled with an image open.

-validateMenuItem: now catches the exception, logs the action and the
exception, and disables only that item for this pass. The rest of the menu is
still checked, and the next pass checks the item again. This is shared code, so
it applies on every platform.

MenuValidationExceptionProbeTests has three tests:
- a check that raises disables its item and doesn't raise;
- the item after a raising check is still checked;
- GNUstep stops a menu pass at an unguarded raise (GNUstep only).
Without the fix, the first two fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AEr1tY2QmxWFSoDkDHs2DC
@danjboyd
danjboyd merged commit d738bdf into main Nov 18, 2026
4 checks passed
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.

Windows: Edit menu appeared greyed out once

1 participant