Make Window.listDescriptions resilient to malformed descriptors#2
Conversation
Previously listDescriptions mapped every CGWindowList descriptor through the throwing Description initializer, so a single window missing a required key threw the entire call and discarded the whole list. Parse each descriptor independently and skip (with a debug log) any that fail, so one odd system window no longer wipes the results. describe() and all other callers benefit; the throwing signature is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📜 Recent review details🔇 Additional comments (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe PR improves error resilience in window descriptor enumeration. ChangesRobust window descriptor enumeration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR makes Window.listDescriptions resilient to malformed window descriptors returned by CGWindowListCopyWindowInfo, so one bad entry no longer fails the entire listing (benefiting describe() and other callers that enumerate windows).
Changes:
- Replace
try arr.map(...)with per-descriptor parsing usingcompactMap+do/catch. - Skip unparseable descriptors and emit a
debugLogmessage on parse failures.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } catch { | ||
| debugLog("WindowControl: skipping unparseable window descriptor: \(error)") | ||
| return nil | ||
| } |
Summary
Window.listDescriptionsmapped everyCGWindowListCopyWindowInfodescriptor through the throwingDescriptioninitializer (arr.map(...)), so a single window missing a required key (e.g. a system overlay or screen recorder) threw the entire call and discarded the whole list.This parses each descriptor independently and skips (with a
debugLog) any that fail to parse, so one odd window no longer wipes the results.describe()and every other caller benefit. Thethrowssignature is unchanged (it still throwslistingFailedif the CG call itself returns nil).Motivated by a downstream eclipsing-window coordinator in platform-imessage that needs a resilient on-screen window enumeration.
🤖 Generated with Claude Code