Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Catch unexpected exceptions thrown by the alerts monitor #660

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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