Skip to content

Make Window.listDescriptions resilient to malformed descriptors#2

Merged
KishanBagaria merged 1 commit into
mainfrom
kb/listdescriptions-resilient
May 30, 2026
Merged

Make Window.listDescriptions resilient to malformed descriptors#2
KishanBagaria merged 1 commit into
mainfrom
kb/listdescriptions-resilient

Conversation

@KishanBagaria
Copy link
Copy Markdown
Member

Summary

Window.listDescriptions mapped every CGWindowListCopyWindowInfo descriptor through the throwing Description initializer (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. The throws signature is unchanged (it still throws listingFailed if 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

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>
Copilot AI review requested due to automatic review settings May 30, 2026 19:56
@indent
Copy link
Copy Markdown

indent Bot commented May 30, 2026

PR Summary

Makes Window.listDescriptions resilient so a single malformed CGWindowList descriptor (e.g., an unusual system window missing a required key) no longer aborts the entire listing. Each descriptor is now parsed independently; failures are skipped with a debugLog instead of being thrown up to callers. describe() and any other caller benefit, and the throwing signature is unchanged (Error.listingFailed from the outer cast still propagates).

  • Sources/WindowControl/Window.swift: replace try arr.map(Window.Description.init(rawDescriptor:)) with a compactMap that wraps each per-descriptor init in do/catch, logging via debugLog and returning nil on failure.

Issues

No issues found.

CI Checks

Waiting for CI checks...

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5c887af6-1691-4b76-bd01-64fd3c4efcd1

📥 Commits

Reviewing files that changed from the base of the PR and between 9115c52 and e69f480.

📒 Files selected for processing (1)
  • Sources/WindowControl/Window.swift
📜 Recent review details
🔇 Additional comments (1)
Sources/WindowControl/Window.swift (1)

236-243: LGTM!


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved system resilience by enhancing window descriptor parsing to gracefully handle invalid entries, allowing continued operation instead of failure when encountering malformed data.

Walkthrough

The PR improves error resilience in window descriptor enumeration. Window.listDescriptions now uses compactMap with per-descriptor error handling instead of a throwing map, allowing it to gracefully skip unparseable window entries while logging debug information.

Changes

Robust window descriptor enumeration

Layer / File(s) Summary
Graceful descriptor parsing with debug logging
Sources/WindowControl/Window.swift
listDescriptions replaces all-or-nothing descriptor mapping with per-descriptor do/try/catch inside compactMap, logging failures and omitting invalid entries from results.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main change: making Window.listDescriptions resilient to malformed descriptors, which is the core objective of the PR.
Description check ✅ Passed The description is directly related to the changeset, explaining the motivation, problem being solved, and implementation approach with clear details about the changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch kb/listdescriptions-resilient

Comment @coderabbitai help to get the list of available commands and usage tips.

@KishanBagaria KishanBagaria merged commit 6c1c20f into main May 30, 2026
0 of 3 checks passed
@KishanBagaria KishanBagaria deleted the kb/listdescriptions-resilient branch May 30, 2026 19:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 using compactMap + do/catch.
  • Skip unparseable descriptors and emit a debugLog message on parse failures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +239 to +242
} catch {
debugLog("WindowControl: skipping unparseable window descriptor: \(error)")
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants