tmandry / Swindler

macOS window management library for Swift
https://tmandry.github.io/Swindler/docs/main/
MIT License
695 stars 66 forks source link

fatal error: State can't become invalid #10

Closed stphivos closed 6 years ago

stphivos commented 7 years ago

A simple call to either:

let primaryScreen: Screen = Swindler.state.screens.first!

or

let windows: [Window] = Swindler.state.knownWindows

in the view controller after the call to super:

override func viewDidLoad() {
    super.viewDidLoad()
}

causes assertionFailure("State can't become invalid") and the app is forced to exit. I tried having different combinations of open windows (Chrome, Sublime, etc.) including none. For some mysterious reason, only when I have Atom open the invalid state assertion doesn't get called and I only get the standard debug/notice log messages in the console.

I tried using a deferred call in case this happens due to a race condition:

override func viewDidLoad() {
    super.viewDidLoad()
    DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(5000), execute: {
        let primaryScreen: Screen = Swindler.state.screens.first!
    }
}

without any luck.

My project is a standard Cocoa application and versions info:

OS: Sierra 10.12.6
Xcode: 8.3.3 (8E3004b)
Swift: 3.1

Error & Traceback:

state_invalid_error

fatal error: State can't become invalid: file /Users/stphivos/Projects/Swindler/Swindler/State.swift, line 344
2017-09-21 03:52:19.607833+0300 TestProject[31242:2375701] fatal error: State can't become invalid: file /Users/stphivos/Projects/Swindler/Swindler/State.swift, line 344
Sep 21 03:52:19  TestProject[31242] <Error>: fatal error: State can't become invalid: file /Users/stphivos/Projects/Swindler/Swindler/State.swift, line 344
Current stack trace:
0    libswiftCore.dylib                 0x000000010056a130 swift_reportError + 129
1    libswiftCore.dylib                 0x0000000100586a40 _swift_stdlib_reportFatalErrorInFile + 100
2    libswiftCore.dylib                 0x0000000100377ba0 (_assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #1).(closure #1).(closure #1) + 124
3    libswiftCore.dylib                 0x000000010052e360 partial apply for (_assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #1).(closure #1).(closure #1) + 93
4    libswiftCore.dylib                 0x0000000100377250 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342
5    libswiftCore.dylib                 0x0000000100530880 partial apply for (_assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #1).(closure #1) + 144
6    libswiftCore.dylib                 0x0000000100377760 specialized specialized String._withUnsafeBufferPointerToUTF8<A> ((UnsafeBufferPointer<UInt8>) throws -> A) throws -> A + 127
7    libswiftCore.dylib                 0x00000001004f1f40 partial apply for (_assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #1) + 185
8    libswiftCore.dylib                 0x0000000100377250 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342
9    libswiftCore.dylib                 0x00000001004a8130 specialized _assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never + 144
10   libswiftCore.dylib                 0x0000000100377140 assertionFailure(@autoclosure () -> String, file : StaticString, line : UInt) -> () + 96
11   Swindler                           0x000000010010f4f0 OSXStateDelegate.notifyInvalid() -> () + 88
12   Swindler                           0x000000010010f5f0 protocol witness for PropertyNotifier.notifyInvalid() -> () in conformance <A, B, C where ...> OSXStateDelegate<A, B, C> + 40
13   Swindler                           0x00000001000fd030 PropertyNotifierThunk.(init<A, B, C where ...> (A1, withEvent : B1.Type, receivingObject : C1.Type) -> PropertyNotifierThunk<A>).(closure #1) + 127
14   Swindler                           0x00000001000fd130 partial apply for PropertyNotifierThunk.(init<A, B, C where ...> (A1, withEvent : B1.Type, receivingObject : C1.Type) -> PropertyNotifierThunk<A>).(closure #1) + 136
15   Swindler                           0x00000001000f89a0 Property.handleError(Error) throws -> A.PropertyType + 1137
16   Swindler                           0x00000001000f6a00 Property.(init<A, B where ...> (A1, notifier : B1) -> Property<A>).(closure #2) + 191
17   Swindler                           0x00000001000f6bc0 partial apply for Property.(init<A, B where ...> (A1, notifier : B1) -> Property<A>).(closure #2) + 159
18   PromiseKit                         0x0000000100279750 State.(catch(on : DispatchQueue, policy : CatchPolicy, else : (Resolution<A>) -> (), execute : (Error) throws -> ()) -> ()).(closure #1).(closure #1) + 113
19   PromiseKit                         0x0000000100290a20 (contain_zalgo<A> (DispatchQueue, rejecter : (Resolution<A>) -> (), block : () throws -> ()) -> ()).(closure #1) + 137
20   PromiseKit                         0x000000010024fdc0 thunk + 39
21   libdispatch.dylib                  0x0000000100c57cf2 _dispatch_call_block_and_release + 12
22   libdispatch.dylib                  0x0000000100c4e784 _dispatch_client_callout + 8
23   libdispatch.dylib                  0x0000000100c5c95a _dispatch_main_queue_callback_4CF + 362
24   CoreFoundation                     0x00007fff8917abc0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
25   CoreFoundation                     0x00007fff8913b370 __CFRunLoopRun + 2205
26   CoreFoundation                     0x00007fff8913af70 CFRunLoopRunSpecific + 420
27   HIToolbox                          0x00007fff8869bdcc RunCurrentEventLoopInMode + 240
28   HIToolbox                          0x00007fff8869bb41 ReceiveNextEventCommon + 432
29   HIToolbox                          0x00007fff8869badf _BlockUntilNextEventMatchingListInModeWithFilter + 71
30   AppKit                             0x00007fff86c345f4 _DPSNextEvent + 1120
31   AppKit                             0x00007fff873afd02 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
32   AppKit                             0x00007fff86c2903d -[NSApplication run] + 926
33   AppKit                             0x00007fff86bf3939 NSApplicationMain + 1237
34   TestProject                        0x000000010000f900 main + 13
35   libdyld.dylib                      0x00007fff9e8c3234 start + 1
(lldb)

Any thoughts how to overcome this?

tmandry commented 7 years ago

Thanks for the detailed report. I added some debug logs to target this. Can you build from latest master and paste the log you get?

stphivos commented 7 years ago

Sure. While having the following open windows: Chrome, Sublime Text, Terminal and trying to query Swindler it fails and I'm getting this log (no indication of AXError.invalidUIElement):

2017-09-25 04:12:26.552608+0300 TestProject[3978:99653] Initializing Swindler
Sep 25 04:12:26  TestProject[3978] <Debug>: Initializing Swindler
2017-09-25 04:12:27.277319+0300 TestProject[3978:99653] Application invalidated: com.fips.TestProject
Sep 25 04:12:27  TestProject[3978] <Debug>: Application invalidated: com.fips.TestProject
2017-09-25 04:12:27.277656+0300 TestProject[3978:99653] Application invalidated: com.apple.dock
Sep 25 04:12:27  TestProject[3978] <Debug>: Application invalidated: com.apple.dock
2017-09-25 04:12:27.278422+0300 TestProject[3978:99653] Window <AXWindow "Window" (pid=364)> has subrole AXUnknown, unwatching
Sep 25 04:12:27  TestProject[3978] <Debug>: Window <AXWindow "Window" (pid=364)> has subrole AXUnknown, unwatching
2017-09-25 04:12:27.279001+0300 TestProject[3978:99653] Window <AXUnknown "<AXUIElement 0x61800004e130> {pid=543}" (pid=543)> has subrole AXUnknown, unwatching
Sep 25 04:12:27  TestProject[3978] <Debug>: Window <AXUnknown "<AXUIElement 0x61800004e130> {pid=543}" (pid=543)> has subrole AXUnknown, unwatching
2017-09-25 04:12:27.283515+0300 TestProject[3978:99653] Couldn't initialize window for element <AXWindow "Window" (pid=364)> () of com.apogee.ApogeePopup: windowIgnored(<AXWindow "Window" (pid=364)>)
Sep 25 04:12:27  TestProject[3978] <Debug>: Couldn't initialize window for element <AXWindow "Window" (pid=364)> () of com.apogee.ApogeePopup: windowIgnored(<AXWindow "Window" (pid=364)>)
2017-09-25 04:12:27.284471+0300 TestProject[3978:99653] Couldn't initialize window for element <AXUnknown "<AXUIElement 0x61800004e130> {pid=543}" (pid=543)> () of com.google.Chrome: windowIgnored(<AXUnknown "<AXUIElement 0x61800004e130> {pid=543}" (pid=543)>)
Sep 25 04:12:27  TestProject[3978] <Debug>: Couldn't initialize window for element <AXUnknown "<AXUIElement 0x61800004e130> {pid=543}" (pid=543)> () of com.google.Chrome: windowIgnored(<AXUnknown "<AXUIElement 0x61800004e130> {pid=543}" (pid=543)>)
2017-09-25 04:12:27.285786+0300 TestProject[3978:99653] Couldn't initialize window for element <AXScrollArea "<AXUIElement 0x6000000582d0> {pid=319}" (pid=319)> (desktop) of com.apple.finder: AXError.NotificationUnsupported
Sep 25 04:12:27  TestProject[3978] <Debug>: Couldn't initialize window for element <AXScrollArea "<AXUIElement 0x6000000582d0> {pid=319}" (pid=319)> (desktop) of com.apple.finder: AXError.NotificationUnsupported
2017-09-25 04:12:27.288427+0300 TestProject[3978:99653] Application invalidated: com.apple.dock
Sep 25 04:12:27  TestProject[3978] <Debug>: Application invalidated: com.apple.dock
2017-09-25 04:12:27.291689+0300 TestProject[3978:99653] Application invalidated: com.apple.dock
Sep 25 04:12:27  TestProject[3978] <Debug>: Application invalidated: com.apple.dock
2017-09-25 04:12:27.293714+0300 TestProject[3978:99653] Application invalidated: com.apple.dock
Sep 25 04:12:27  TestProject[3978] <Debug>: Application invalidated: com.apple.dock
2017-09-25 04:12:27.294421+0300 TestProject[3978:99653] Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
Sep 25 04:12:27  TestProject[3978] <Notice>: Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
2017-09-25 04:12:27.294790+0300 TestProject[3978:99653] Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
Sep 25 04:12:27  TestProject[3978] <Notice>: Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
2017-09-25 04:12:27.295104+0300 TestProject[3978:99653] Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
Sep 25 04:12:27  TestProject[3978] <Notice>: Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
2017-09-25 04:12:27.295343+0300 TestProject[3978:99653] Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
Sep 25 04:12:27  TestProject[3978] <Notice>: Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
fatal error: State can't become invalid: file /Users/stphivos/Projects/Swindler/Swindler/State.swift, line 344
2017-09-25 04:12:27.295764+0300 TestProject[3978:99653] fatal error: State can't become invalid: file /Users/stphivos/Projects/Swindler/Swindler/State.swift, line 344
Sep 25 04:12:27  TestProject[3978] <Error>: fatal error: State can't become invalid: file /Users/stphivos/Projects/Swindler/Swindler/State.swift, line 344
Current stack trace:
0    libswiftCore.dylib                 0x0000000100588130 swift_reportError + 129
1    libswiftCore.dylib                 0x00000001005a4a40 _swift_stdlib_reportFatalErrorInFile + 100
2    libswiftCore.dylib                 0x0000000100395ba0 (_assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #1).(closure #1).(closure #1) + 124
3    libswiftCore.dylib                 0x000000010054c360 partial apply for (_assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #1).(closure #1).(closure #1) + 93
4    libswiftCore.dylib                 0x0000000100395250 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342
5    libswiftCore.dylib                 0x000000010054e880 partial apply for (_assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #1).(closure #1) + 144
6    libswiftCore.dylib                 0x0000000100395760 specialized specialized String._withUnsafeBufferPointerToUTF8<A> ((UnsafeBufferPointer<UInt8>) throws -> A) throws -> A + 127
7    libswiftCore.dylib                 0x000000010050ff40 partial apply for (_assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #1) + 185
8    libswiftCore.dylib                 0x0000000100395250 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342
9    libswiftCore.dylib                 0x00000001004c6130 specialized _assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never + 144
10   libswiftCore.dylib                 0x0000000100395140 assertionFailure(@autoclosure () -> String, file : StaticString, line : UInt) -> () + 96
11   Swindler                           0x000000010012d160 OSXStateDelegate.notifyInvalid() -> () + 88
12   Swindler                           0x000000010012d260 protocol witness for PropertyNotifier.notifyInvalid() -> () in conformance <A, B, C where ...> OSXStateDelegate<A, B, C> + 40
13   Swindler                           0x000000010011aca0 PropertyNotifierThunk.(init<A, B, C where ...> (A1, withEvent : B1.Type, receivingObject : C1.Type) -> PropertyNotifierThunk<A>).(closure #1) + 127
14   Swindler                           0x000000010011ada0 partial apply for PropertyNotifierThunk.(init<A, B, C where ...> (A1, withEvent : B1.Type, receivingObject : C1.Type) -> PropertyNotifierThunk<A>).(closure #1) + 136
15   Swindler                           0x0000000100116610 Property.handleError(Error) throws -> A.PropertyType + 1137
16   Swindler                           0x0000000100114670 Property.(init<A, B where ...> (A1, notifier : B1) -> Property<A>).(closure #2) + 191
17   Swindler                           0x0000000100114830 partial apply for Property.(init<A, B where ...> (A1, notifier : B1) -> Property<A>).(closure #2) + 159
18   PromiseKit                         0x0000000100297750 State.(catch(on : DispatchQueue, policy : CatchPolicy, else : (Resolution<A>) -> (), execute : (Error) throws -> ()) -> ()).(closure #1).(closure #1) + 113
19   PromiseKit                         0x00000001002aea20 (contain_zalgo<A> (DispatchQueue, rejecter : (Resolution<A>) -> (), block : () throws -> ()) -> ()).(closure #1) + 137
20   PromiseKit                         0x000000010026ddc0 thunk + 39
21   libdispatch.dylib                  0x0000000100c75cf2 _dispatch_call_block_and_release + 12
22   libdispatch.dylib                  0x0000000100c6c784 _dispatch_client_callout + 8
23   libdispatch.dylib                  0x0000000100c7a95a _dispatch_main_queue_callback_4CF + 362
24   CoreFoundation                     0x00007fff82971bc0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
25   CoreFoundation                     0x00007fff82932370 __CFRunLoopRun + 2205
26   CoreFoundation                     0x00007fff82931f70 CFRunLoopRunSpecific + 420
27   HIToolbox                          0x00007fff81e92dcc RunCurrentEventLoopInMode + 240
28   HIToolbox                          0x00007fff81e92b41 ReceiveNextEventCommon + 432
29   HIToolbox                          0x00007fff81e92adf _BlockUntilNextEventMatchingListInModeWithFilter + 71
30   AppKit                             0x00007fff8042b5f4 _DPSNextEvent + 1120
31   AppKit                             0x00007fff80ba6d02 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
32   AppKit                             0x00007fff8042003d -[NSApplication run] + 926
33   AppKit                             0x00007fff803ea939 NSApplicationMain + 1237
34   TestProject                        0x000000010001a1d0 main + 13
35   libdyld.dylib                      0x00007fff980ba234 start + 1
(lldb) 

But when I also open an instance of Atom my TestProject doesn't crash and I get this shorter log:

2017-09-25 04:12:49.825586+0300 TestProject[4227:101246] Initializing Swindler
Sep 25 04:12:49  TestProject[4227] <Debug>: Initializing Swindler
2017-09-25 04:12:50.052035+0300 TestProject[4227:101246] Application invalidated: com.fips.TestProject
Sep 25 04:12:50  TestProject[4227] <Debug>: Application invalidated: com.fips.TestProject
2017-09-25 04:12:50.052407+0300 TestProject[4227:101246] Application invalidated: com.apple.dock
Sep 25 04:12:50  TestProject[4227] <Debug>: Application invalidated: com.apple.dock
2017-09-25 04:12:50.053093+0300 TestProject[4227:101246] Window <AXWindow "Window" (pid=364)> has subrole AXUnknown, unwatching
Sep 25 04:12:50  TestProject[4227] <Debug>: Window <AXWindow "Window" (pid=364)> has subrole AXUnknown, unwatching
2017-09-25 04:12:50.053781+0300 TestProject[4227:101246] Window <AXUnknown "<AXUIElement 0x600000046960> {pid=543}" (pid=543)> has subrole AXUnknown, unwatching
Sep 25 04:12:50  TestProject[4227] <Debug>: Window <AXUnknown "<AXUIElement 0x600000046960> {pid=543}" (pid=543)> has subrole AXUnknown, unwatching
2017-09-25 04:12:50.184900+0300 TestProject[4227:101246] Couldn't initialize window for element <AXWindow "Window" (pid=364)> () of com.apogee.ApogeePopup: windowIgnored(<AXWindow "Window" (pid=364)>)
Sep 25 04:12:50  TestProject[4227] <Debug>: Couldn't initialize window for element <AXWindow "Window" (pid=364)> () of com.apogee.ApogeePopup: windowIgnored(<AXWindow "Window" (pid=364)>)
2017-09-25 04:12:50.187292+0300 TestProject[4227:101246] Couldn't initialize window for element <AXScrollArea "<AXUIElement 0x600000046240> {pid=319}" (pid=319)> (desktop) of com.apple.finder: AXError.NotificationUnsupported
Sep 25 04:12:50  TestProject[4227] <Debug>: Couldn't initialize window for element <AXScrollArea "<AXUIElement 0x600000046240> {pid=319}" (pid=319)> (desktop) of com.apple.finder: AXError.NotificationUnsupported
2017-09-25 04:12:50.188502+0300 TestProject[4227:101246] Couldn't initialize window for element <AXUnknown "<AXUIElement 0x600000046960> {pid=543}" (pid=543)> () of com.google.Chrome: windowIgnored(<AXUnknown "<AXUIElement 0x600000046960> {pid=543}" (pid=543)>)
Sep 25 04:12:50  TestProject[4227] <Debug>: Couldn't initialize window for element <AXUnknown "<AXUIElement 0x600000046960> {pid=543}" (pid=543)> () of com.google.Chrome: windowIgnored(<AXUnknown "<AXUIElement 0x600000046960> {pid=543}" (pid=543)>)
2017-09-25 04:12:50.189973+0300 TestProject[4227:101246] Application invalidated: com.apple.dock
Sep 25 04:12:50  TestProject[4227] <Debug>: Application invalidated: com.apple.dock
2017-09-25 04:12:50.195038+0300 TestProject[4227:101246] Application invalidated: com.apple.dock
Sep 25 04:12:50  TestProject[4227] <Debug>: Application invalidated: com.apple.dock
2017-09-25 04:12:50.198243+0300 TestProject[4227:101246] Application invalidated: com.apple.dock
Sep 25 04:12:50  TestProject[4227] <Debug>: Application invalidated: com.apple.dock
2017-09-25 04:12:50.199438+0300 TestProject[4227:101246] Could not watch application com.github.atom.helper (pid=3988): timeout(-1.0)
Sep 25 04:12:50  TestProject[4227] <Notice>: Could not watch application com.github.atom.helper (pid=3988): timeout(-1.0)
2017-09-25 04:12:50.199657+0300 TestProject[4227:101246] Could not watch application com.github.atom.helper (pid=4225): timeout(-1.0)
Sep 25 04:12:50  TestProject[4227] <Notice>: Could not watch application com.github.atom.helper (pid=4225): timeout(-1.0)
2017-09-25 04:12:50.199885+0300 TestProject[4227:101246] Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
Sep 25 04:12:50  TestProject[4227] <Notice>: Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
2017-09-25 04:12:50.200710+0300 TestProject[4227:101246] Could not watch application com.github.atom.helper (pid=3988): timeout(-1.0)
Sep 25 04:12:50  TestProject[4227] <Notice>: Could not watch application com.github.atom.helper (pid=3988): timeout(-1.0)
2017-09-25 04:12:50.200913+0300 TestProject[4227:101246] Could not watch application com.github.atom.helper (pid=4225): timeout(-1.0)
Sep 25 04:12:50  TestProject[4227] <Notice>: Could not watch application com.github.atom.helper (pid=4225): timeout(-1.0)
2017-09-25 04:12:50.201110+0300 TestProject[4227:101246] Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
Sep 25 04:12:50  TestProject[4227] <Notice>: Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
2017-09-25 04:12:50.201424+0300 TestProject[4227:101246] Could not watch application com.github.atom.helper (pid=3988): timeout(-1.0)
Sep 25 04:12:50  TestProject[4227] <Notice>: Could not watch application com.github.atom.helper (pid=3988): timeout(-1.0)
2017-09-25 04:12:50.201594+0300 TestProject[4227:101246] Could not watch application com.github.atom.helper (pid=4225): timeout(-1.0)
Sep 25 04:12:50  TestProject[4227] <Notice>: Could not watch application com.github.atom.helper (pid=4225): timeout(-1.0)
2017-09-25 04:12:50.201777+0300 TestProject[4227:101246] Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
Sep 25 04:12:50  TestProject[4227] <Notice>: Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
2017-09-25 04:12:50.202025+0300 TestProject[4227:101246] Could not watch application com.github.atom.helper (pid=3988): timeout(-1.0)
Sep 25 04:12:50  TestProject[4227] <Notice>: Could not watch application com.github.atom.helper (pid=3988): timeout(-1.0)
2017-09-25 04:12:50.202328+0300 TestProject[4227:101246] Could not watch application com.github.atom.helper (pid=4225): timeout(-1.0)
Sep 25 04:12:50  TestProject[4227] <Notice>: Could not watch application com.github.atom.helper (pid=4225): timeout(-1.0)
2017-09-25 04:12:50.202507+0300 TestProject[4227:101246] Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
Sep 25 04:12:50  TestProject[4227] <Notice>: Could not watch application com.apple.dock (pid=316): invalidObject(AXError.NotificationUnsupported)
2017-09-25 04:12:50.202897+0300 TestProject[4227:101246] Caught error: timeout(-1.0)
Sep 25 04:12:50  TestProject[4227] <Error>: Caught error: timeout(-1.0)
2017-09-25 04:12:50.202928+0300 TestProject[4227:101246] Done initializing
Sep 25 04:12:50  TestProject[4227] <Debug>: Done initializing
2017-09-25 04:12:50.203135+0300 TestProject[4227:101246] PromiseKit: unhandled error: Error Domain=Swindler.PropertyError Code=0 "(null)"
2017-09-25 04:12:50.203203+0300 TestProject[4227:101246] PromiseKit: unhandled error: Error Domain=Swindler.PropertyError Code=0 "(null)"
2017-09-25 04:12:50.203251+0300 TestProject[4227:101246] PromiseKit: unhandled error: Error Domain=Swindler.PropertyError Code=0 "(null)"
2017-09-25 04:12:51.580605+0300 TestProject[4227:101246] PromiseKit: unhandled error: Error Domain=Swindler.PropertyError Code=0 "(null)"
2017-09-25 04:12:51.580746+0300 TestProject[4227:101246] PromiseKit: unhandled error: Error Domain=Swindler.PropertyError Code=0 "(null)"

Thanks for your help!

tmandry commented 7 years ago

Apparently I missed a couple cases. I pushed an update to master with those. Hopefully you get more informative output this time around. Thanks for your patience.

stphivos commented 7 years ago

No worries, lot's of output now!

2017-09-26 04:30:39.285162+0300 TestProject[545:5627] Initializing Swindler
Sep 26 04:30:39  TestProject[545] <Debug>: Initializing Swindler
2017-09-26 04:30:39.708252+0300 TestProject[545:5627] Got error while initializing attribute mainWindow for element <AXApplication "com.fips.TestProject" (pid=545)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute mainWindow for element <AXApplication "com.fips.TestProject" (pid=545)>
2017-09-26 04:30:39.708708+0300 TestProject[545:5627] Got error while initializing attribute focusedWindow for element <AXApplication "com.fips.TestProject" (pid=545)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute focusedWindow for element <AXApplication "com.fips.TestProject" (pid=545)>
2017-09-26 04:30:39.708890+0300 TestProject[545:5627] Got error while initializing attribute hidden for element <AXApplication "com.fips.TestProject" (pid=545)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute hidden for element <AXApplication "com.fips.TestProject" (pid=545)>
2017-09-26 04:30:39.710073+0300 TestProject[545:5627] Got error while initializing attribute mainWindow for element <AXApplication "com.apple.dock" (pid=327)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute mainWindow for element <AXApplication "com.apple.dock" (pid=327)>
2017-09-26 04:30:39.710370+0300 TestProject[545:5627] Got error while initializing attribute focusedWindow for element <AXApplication "com.apple.dock" (pid=327)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute focusedWindow for element <AXApplication "com.apple.dock" (pid=327)>
2017-09-26 04:30:39.710705+0300 TestProject[545:5627] Got error while initializing attribute hidden for element <AXApplication "com.apple.dock" (pid=327)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute hidden for element <AXApplication "com.apple.dock" (pid=327)>
2017-09-26 04:30:39.714556+0300 TestProject[545:5627] Marking property of type Optional<Window> invalid: invalidObject(AXError.NotImplemented)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Optional<Window> invalid: invalidObject(AXError.NotImplemented)
2017-09-26 04:30:39.714666+0300 TestProject[545:5627] Application invalidated: com.fips.TestProject
Sep 26 04:30:39  TestProject[545] <Debug>: Application invalidated: com.fips.TestProject
2017-09-26 04:30:39.714875+0300 TestProject[545:5627] Marking property of type Optional<Window> invalid: invalidObject(AXError.NotImplemented)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Optional<Window> invalid: invalidObject(AXError.NotImplemented)
2017-09-26 04:30:39.715008+0300 TestProject[545:5627] Marking property of type Bool invalid: invalidObject(AXError.NotImplemented)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Bool invalid: invalidObject(AXError.NotImplemented)
2017-09-26 04:30:39.715115+0300 TestProject[545:5627] Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.715300+0300 TestProject[545:5627] Application invalidated: com.apple.dock
Sep 26 04:30:39  TestProject[545] <Debug>: Application invalidated: com.apple.dock
2017-09-26 04:30:39.715445+0300 TestProject[545:5627] Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.715507+0300 TestProject[545:5627] Marking property of type Bool invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Bool invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.716208+0300 TestProject[545:5627] Window <AXWindow "Window" (pid=391)> has subrole AXUnknown, unwatching
Sep 26 04:30:39  TestProject[545] <Debug>: Window <AXWindow "Window" (pid=391)> has subrole AXUnknown, unwatching
2017-09-26 04:30:39.720019+0300 TestProject[545:5627] Got error while initializing attribute mainWindow for element <AXApplication "com.apple.dock" (pid=327)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute mainWindow for element <AXApplication "com.apple.dock" (pid=327)>
2017-09-26 04:30:39.720327+0300 TestProject[545:5627] Got error while initializing attribute focusedWindow for element <AXApplication "com.apple.dock" (pid=327)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute focusedWindow for element <AXApplication "com.apple.dock" (pid=327)>
2017-09-26 04:30:39.720627+0300 TestProject[545:5627] Got error while initializing attribute hidden for element <AXApplication "com.apple.dock" (pid=327)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute hidden for element <AXApplication "com.apple.dock" (pid=327)>
2017-09-26 04:30:39.722656+0300 TestProject[545:5627] Couldn't initialize window for element <AXWindow "Window" (pid=391)> () of com.apogee.ApogeePopup: windowIgnored(<AXWindow "Window" (pid=391)>)
Sep 26 04:30:39  TestProject[545] <Debug>: Couldn't initialize window for element <AXWindow "Window" (pid=391)> () of com.apogee.ApogeePopup: windowIgnored(<AXWindow "Window" (pid=391)>)
2017-09-26 04:30:39.723322+0300 TestProject[545:5627] Got error while initializing attribute position for element <AXScrollArea "<AXUIElement 0x600000453320> {pid=330}" (pid=330)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute position for element <AXScrollArea "<AXUIElement 0x600000453320> {pid=330}" (pid=330)>
2017-09-26 04:30:39.723750+0300 TestProject[545:5627] Got error while initializing attribute size for element <AXScrollArea "<AXUIElement 0x600000453320> {pid=330}" (pid=330)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute size for element <AXScrollArea "<AXUIElement 0x600000453320> {pid=330}" (pid=330)>
2017-09-26 04:30:39.724268+0300 TestProject[545:5627] Got error while initializing attribute title for element <AXScrollArea "<AXUIElement 0x600000453320> {pid=330}" (pid=330)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute title for element <AXScrollArea "<AXUIElement 0x600000453320> {pid=330}" (pid=330)>
2017-09-26 04:30:39.724680+0300 TestProject[545:5627] Got error while initializing attribute minimized for element <AXScrollArea "<AXUIElement 0x600000453320> {pid=330}" (pid=330)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute minimized for element <AXScrollArea "<AXUIElement 0x600000453320> {pid=330}" (pid=330)>
2017-09-26 04:30:39.725082+0300 TestProject[545:5627] Got error while initializing attribute fullScreen for element <AXScrollArea "<AXUIElement 0x600000453320> {pid=330}" (pid=330)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute fullScreen for element <AXScrollArea "<AXUIElement 0x600000453320> {pid=330}" (pid=330)>
2017-09-26 04:30:39.727959+0300 TestProject[545:5627] Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.728173+0300 TestProject[545:5627] Application invalidated: com.apple.dock
Sep 26 04:30:39  TestProject[545] <Debug>: Application invalidated: com.apple.dock
2017-09-26 04:30:39.728374+0300 TestProject[545:5627] Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.728442+0300 TestProject[545:5627] Marking property of type Bool invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Bool invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.729217+0300 TestProject[545:5627] Marking property of type CGPoint invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type CGPoint invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.729371+0300 TestProject[545:5627] Marking property of type CGSize invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type CGSize invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.729481+0300 TestProject[545:5627] Marking property of type String invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type String invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.729538+0300 TestProject[545:5627] Marking property of type Bool invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Bool invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.729592+0300 TestProject[545:5627] Marking property of type Bool invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Bool invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.730438+0300 TestProject[545:5627] Couldn't initialize window for element <AXScrollArea "<AXUIElement 0x600000453320> {pid=330}" (pid=330)> (desktop) of com.apple.finder: AXError.NotificationUnsupported
Sep 26 04:30:39  TestProject[545] <Debug>: Couldn't initialize window for element <AXScrollArea "<AXUIElement 0x600000453320> {pid=330}" (pid=330)> (desktop) of com.apple.finder: AXError.NotificationUnsupported
2017-09-26 04:30:39.731825+0300 TestProject[545:5627] Got error while initializing attribute mainWindow for element <AXApplication "com.apple.dock" (pid=327)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute mainWindow for element <AXApplication "com.apple.dock" (pid=327)>
2017-09-26 04:30:39.732127+0300 TestProject[545:5627] Got error while initializing attribute focusedWindow for element <AXApplication "com.apple.dock" (pid=327)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute focusedWindow for element <AXApplication "com.apple.dock" (pid=327)>
2017-09-26 04:30:39.732426+0300 TestProject[545:5627] Got error while initializing attribute hidden for element <AXApplication "com.apple.dock" (pid=327)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute hidden for element <AXApplication "com.apple.dock" (pid=327)>
2017-09-26 04:30:39.733152+0300 TestProject[545:5627] Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.733297+0300 TestProject[545:5627] Application invalidated: com.apple.dock
Sep 26 04:30:39  TestProject[545] <Debug>: Application invalidated: com.apple.dock
2017-09-26 04:30:39.733475+0300 TestProject[545:5627] Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.733556+0300 TestProject[545:5627] Marking property of type Bool invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Bool invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.734982+0300 TestProject[545:5627] Got error while initializing attribute focusedWindow for element <AXApplication "com.apple.dock" (pid=327)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute focusedWindow for element <AXApplication "com.apple.dock" (pid=327)>
2017-09-26 04:30:39.735254+0300 TestProject[545:5627] Got error while initializing attribute mainWindow for element <AXApplication "com.apple.dock" (pid=327)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute mainWindow for element <AXApplication "com.apple.dock" (pid=327)>
2017-09-26 04:30:39.735511+0300 TestProject[545:5627] Got error while initializing attribute hidden for element <AXApplication "com.apple.dock" (pid=327)>
Sep 26 04:30:39  TestProject[545] <Debug>: Got error while initializing attribute hidden for element <AXApplication "com.apple.dock" (pid=327)>
2017-09-26 04:30:39.735829+0300 TestProject[545:5627] Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.735966+0300 TestProject[545:5627] Application invalidated: com.apple.dock
Sep 26 04:30:39  TestProject[545] <Debug>: Application invalidated: com.apple.dock
2017-09-26 04:30:39.736119+0300 TestProject[545:5627] Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Optional<Window> invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.736187+0300 TestProject[545:5627] Marking property of type Bool invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Bool invalid: invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.736707+0300 TestProject[545:5627] Could not watch application com.apple.dock (pid=327): invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Notice>: Could not watch application com.apple.dock (pid=327): invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.737032+0300 TestProject[545:5627] Could not watch application com.apple.dock (pid=327): invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Notice>: Could not watch application com.apple.dock (pid=327): invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.737249+0300 TestProject[545:5627] Could not watch application com.apple.dock (pid=327): invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Notice>: Could not watch application com.apple.dock (pid=327): invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.737529+0300 TestProject[545:5627] Could not watch application com.apple.dock (pid=327): invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Notice>: Could not watch application com.apple.dock (pid=327): invalidObject(AXError.NotificationUnsupported)
2017-09-26 04:30:39.737818+0300 TestProject[545:5627] Marking property of type Optional<Application> invalid: invalidObject(AXError.NotificationUnsupported)
Sep 26 04:30:39  TestProject[545] <Debug>: Marking property of type Optional<Application> invalid: invalidObject(AXError.NotificationUnsupported)
fatal error: State can't become invalid: file /Users/stphivos/Projects/Swindler/Swindler/State.swift, line 344
2017-09-26 04:30:39.737942+0300 TestProject[545:5627] fatal error: State can't become invalid: file /Users/stphivos/Projects/Swindler/Swindler/State.swift, line 344
Sep 26 04:30:39  TestProject[545] <Error>: fatal error: State can't become invalid: file /Users/stphivos/Projects/Swindler/Swindler/State.swift, line 344
(lldb) 
tmandry commented 7 years ago

It looks like expected errors from Application initialization are getting incorrectly forwarded to the property initialization.

Please build from branch fix-invalid-state and see if that fixes the issue. If that is it, I don't understand why it didn't always happen and why I'm not reproducing the issue...

If that doesn't fix it, you are probably safe commenting out the assertionFailure line for now - but I still want to find out what's going on!

stphivos commented 7 years ago

Thanks for the quick response. Unfortunately branch fix-invalid-state could not be built because the recover was no longer returning a promise, so I commented out the assertion. It seems to be working well so far, I will post an update if I come across any problems. Let me know in case you need me to test any future updates 👍

tmandry commented 7 years ago

Sorry, should have built it. I updated the branch again for the next time you get a chance to try it out. Thanks.

stphivos commented 7 years ago

Thanks, I updated my local branch. Unfortunately after installing the latest updates for Xcode and Swift 4, I consistently get AXError.CannotComplete for all apps but my Cocoa app that is using Swindler.

Maybe this is a different issue, but after adding some logs the first point of failure seems to be in AXSwift library UIElement.attribute<T> function in the following line:

let error = AXUIElementCopyAttributeValue(element, attribute as CFString, &value)

Element in this case is <UnknownUIElement "<AXUIElement Application 0x60000004ba60> {pid=115}" (pid=115)> and attribute is AXRole. Apple's description in the docs is not very helpful:

kAXErrorCannotComplete

The function cannot complete because messaging has failed in some way.

Not sure where to go from here but I will look into it more and post an update.

tmandry commented 7 years ago

Hmm. Perhaps you need to re-register as a trusted process?

If not, please file a new issue for this and I will look into it as soon as I have time.

thomasjonas commented 7 years ago

I got SwindlerExample[2237:20256535] PromiseKit: unhandled error: Error Domain=Swindler.PropertyError Code=0 "(null)" errors in the Swindler example on the master branch and tried the fix-invalid-state branch. Worked for me, errors were gone :) Not sure if it's related though...