Do not crash if there is no disk, just return nil instance

Summary: This should not affect prod as flipper (also called sonar) should only be an internal debug product but i needed to fix it to start the app.

Reviewed By: jknoxville

Differential Revision: D10156590

fbshipit-source-id: 84a76e5cbe2f4bbe89627895efcfb7e6cdadae13
This commit is contained in:
Jérémie Marguerie
2018-10-04 14:04:54 -07:00
committed by Facebook Github Bot
parent 44fea6b9bc
commit 145b94b47d

View File

@@ -36,7 +36,12 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
static FlipperClient *sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
try {
sharedClient = [[self alloc] init];
} catch (const std::exception &e) {
// fail.
sharedClient = nil;
}
});
return sharedClient;
}
@@ -52,9 +57,9 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
NSFileManager *manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:privateAppDirectory isDirectory:NULL] == NO) {
//TODO: Handle errors properly
[manager createDirectoryAtPath:privateAppDirectory withIntermediateDirectories:YES attributes:nil error:nil];
if ([manager fileExistsAtPath:privateAppDirectory isDirectory:NULL] == NO &&
![manager createDirectoryAtPath:privateAppDirectory withIntermediateDirectories:YES attributes:nil error:nil]) {
return nil;
}
#if TARGET_OS_SIMULATOR
@@ -62,6 +67,7 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
#endif
static const std::string UNKNOWN = std::string("unknown");
try {
facebook::flipper::FlipperClient::init({
{
"localhost",
@@ -76,6 +82,10 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
connectionThread.getEventBase()
});
_cppClient = facebook::flipper::FlipperClient::instance();
} catch (const std::system_error &e) {
// Probably ran out of disk space.
return nil;
}
}
return self;
}