From b6df8b09e55853ea926214dc78c31c3243b98252 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 8 May 2026 09:01:46 +0100 Subject: [PATCH] fix: harden AXorcist command handling --- CHANGELOG.md | 1 + Sources/AXorcist/Core/AXorcist.swift | 4 +++- Sources/AXorcist/Models/JSONPathHintComponent.swift | 8 +------- Sources/AXorcist/Utils/RunningApplicationHelper.swift | 11 ++--------- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c7a89c..4a1ef80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to AXorcist will be documented in this file. ## [Unreleased] ### Fixed +- Unsupported command dispatch now returns an `unknown_command` error instead of trapping, and JSON path hint parsing no longer writes warnings to stdout for unknown attributes. - Preserve CFRange-backed AXValue attributes such as selected text ranges instead of misclassifying raw value 4 as a boolean. Thanks @WinnCook. ## [0.1.2] - 2026-04-28 diff --git a/Sources/AXorcist/Core/AXorcist.swift b/Sources/AXorcist/Core/AXorcist.swift index 61464ba..0d7880f 100644 --- a/Sources/AXorcist/Core/AXorcist.swift +++ b/Sources/AXorcist/Core/AXorcist.swift @@ -198,7 +198,9 @@ public class AXorcist { case let .observe(observeCommand): handleObserve(command: observeCommand) default: - fatalError("Unsupported command type: \(envelope.command)") + .errorResponse( + message: "Unsupported command type: \(envelope.command.type)", + code: .unknownCommand) } } diff --git a/Sources/AXorcist/Models/JSONPathHintComponent.swift b/Sources/AXorcist/Models/JSONPathHintComponent.swift index 094d134..727c4a7 100644 --- a/Sources/AXorcist/Models/JSONPathHintComponent.swift +++ b/Sources/AXorcist/Models/JSONPathHintComponent.swift @@ -67,13 +67,7 @@ public struct JSONPathHintComponent: Codable, Sendable { /// Converts this component to a simple criteria dictionary for use with existing matching logic. public var simpleCriteria: [String: String]? { - guard let resolvedAttributeName = axAttributeName else { - // Log a warning here if this component is used, as it means an invalid attribute type was provided. - // GlobalAXLogger.shared.log(...) or axWarningLog(...) - Requires importing/access - // For now, just return nil. The calling code should handle this. - print("WARNING: JSONPathHintComponent has unrecognized attribute type: \(self.attribute)") - return nil - } + guard let resolvedAttributeName = axAttributeName else { return nil } return [resolvedAttributeName: self.value] } diff --git a/Sources/AXorcist/Utils/RunningApplicationHelper.swift b/Sources/AXorcist/Utils/RunningApplicationHelper.swift index b324511..1142ee9 100644 --- a/Sources/AXorcist/Utils/RunningApplicationHelper.swift +++ b/Sources/AXorcist/Utils/RunningApplicationHelper.swift @@ -6,10 +6,8 @@ // import ApplicationServices -import Foundation -#if canImport(AppKit) import AppKit -#endif +import Foundation #if canImport(CoreGraphics) import CoreGraphics // Added for CGWindowListCopyWindowInfo #endif @@ -49,12 +47,7 @@ public struct RunningApplicationHelper { /// Get the current application public static var currentApplication: NSRunningApplication { - #if canImport(AppKit) - return NSRunningApplication.current - #else - // Fallback - create a minimal implementation - fatalError("NSRunningApplication.current not available on this platform") - #endif + NSRunningApplication.current } /// Get the current application's process info