Skip to content

Commit

Permalink
Fix exception when watching for crash logs fails
Browse files Browse the repository at this point in the history
Reviewed By: lawrencelomax

Differential Revision: D66263401

fbshipit-source-id: 58d5974c03acd68dfb1c0819826dd1c27abc629d
  • Loading branch information
fbgerrit authored and facebook-github-bot committed Nov 21, 2024
1 parent 2123f13 commit 01fe27e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions FBControlCore/Crashes/FBCrashLogNotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ NS_ASSUME_NONNULL_BEGIN
Starts listening for crash logs.
@param onlyNew YES if you only want to ingest crash logs from now, NO to ingest from the beginning of time.
@return the receiver, for chaining.
@return success.
*/
- (instancetype)startListening:(BOOL)onlyNew;
- (BOOL)startListening:(BOOL)onlyNew;

/**
Obtains the next crash log, for a given predicate.
Expand Down
23 changes: 16 additions & 7 deletions FBControlCore/Crashes/FBCrashLogNotifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ - (instancetype)initWithDirectories:(NSArray<NSString *> *)directories store:(FB
return self;
}

- (void)startListening:(BOOL)onlyNew
- (BOOL)startListening:(BOOL)onlyNew
{
if (self.eventStream) {
return;
return YES;
}

FSEventStreamContext context = {
Expand Down Expand Up @@ -120,8 +120,13 @@ - (void)startListening:(BOOL)onlyNew
);
FSEventStreamSetDispatchQueue(eventStream, self.queue);
Boolean started = FSEventStreamStart(eventStream);
NSAssert(started, @"Event Stream could not be started");
if (!started) {
NSLog(@"FS Event Stream could not be started");
return NO;
}

self.eventStream = eventStream;
return YES;
}

@end
Expand Down Expand Up @@ -172,19 +177,23 @@ + (instancetype)sharedInstance

#pragma mark Public Methods

- (instancetype)startListening:(BOOL)onlyNew
- (BOOL)startListening:(BOOL)onlyNew
{
#if defined(__apple_build_version__)
[self.fsEvents startListening:onlyNew];
return [self.fsEvents startListening:onlyNew];
#else
self.sinceDate = NSDate.date;
return YES;
#endif
return self;
}

- (FBFuture<FBCrashLogInfo *> *)nextCrashLogForPredicate:(NSPredicate *)predicate
{
[self startListening:YES];
if (![self startListening:YES]) {
return [[FBControlCoreError
describeFormat:@"Crash Log Info could not be obtained"]
failFuture];
}

#if defined(__apple_build_version__)
return [FBCrashLogNotifier.sharedInstance.fsEvents.store nextCrashLogForMatchingPredicate:predicate];
Expand Down

0 comments on commit 01fe27e

Please sign in to comment.