From e69f480766d0a0222e401a28f1c09e27ef97d823 Mon Sep 17 00:00:00 2001 From: Kishan Bagaria <1093313+KishanBagaria@users.noreply.github.com> Date: Sun, 31 May 2026 01:23:28 +0530 Subject: [PATCH] Make Window.listDescriptions resilient to malformed descriptors 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) --- Sources/WindowControl/Window.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/WindowControl/Window.swift b/Sources/WindowControl/Window.swift index 82ebd1f..6590f87 100644 --- a/Sources/WindowControl/Window.swift +++ b/Sources/WindowControl/Window.swift @@ -233,6 +233,13 @@ public struct Window: Hashable { guard let arr = CGWindowListCopyWindowInfo(rawOptions, windowID) as? [[String: Any]] else { throw Error.listingFailed } - return try arr.map(Window.Description.init(rawDescriptor:)) + return arr.compactMap { rawDescriptor in + do { + return try Window.Description(rawDescriptor: rawDescriptor) + } catch { + debugLog("WindowControl: skipping unparseable window descriptor: \(error)") + return nil + } + } } }