Skip to content

Commit

Permalink
fix: Catch unexpected exceptions thrown by the alerts monitor (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Feb 17, 2023
1 parent a191d51 commit aa22555
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions WebDriverAgentLib/Utilities/FBAlertsMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#import "FBAlert.h"
#import "FBApplication.h"
#import "FBLogger.h"
#import "XCUIApplication+FBAlert.h"

static const NSTimeInterval FB_MONTORING_INTERVAL = 2.0;
Expand Down Expand Up @@ -50,9 +51,16 @@ - (void)scheduleNextTick
dispatch_async(dispatch_get_main_queue(), ^{
NSArray<FBApplication *> *activeApps = FBApplication.fb_activeApplications;
for (FBApplication *activeApp in activeApps) {
XCUIElement *alertElement = activeApp.fb_alertElement;
XCUIElement *alertElement = nil;
@try {
alertElement = activeApp.fb_alertElement;
if (nil != alertElement) {
[self.delegate didDetectAlert:[FBAlert alertWithElement:alertElement]];
}
} @catch (NSException *e) {
[FBLogger logFmt:@"Got an unexpected exception while monitoring alerts: %@\n%@", e.reason, e.callStackSymbols];
}
if (nil != alertElement) {
[self.delegate didDetectAlert:[FBAlert alertWithElement:alertElement]];
break;
}
}
Expand Down

0 comments on commit aa22555

Please sign in to comment.