Skip to content

Commit

Permalink
Add error resilience to calls to 3rd party libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
ThexXTURBOXx committed Oct 28, 2023
1 parent baaa600 commit 9eb615e
Showing 1 changed file with 51 additions and 42 deletions.
93 changes: 51 additions & 42 deletions lib/core/catcher_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,39 +247,43 @@ class Catcher2 implements ReportModeAction {
}

void _loadDeviceInfo() {
final deviceInfo = DeviceInfoPlugin();
if (ApplicationProfileManager.isWeb()) {
deviceInfo.webBrowserInfo.then((webBrowserInfo) {
_loadWebParameters(webBrowserInfo);
_removeExcludedParameters();
});
} else if (ApplicationProfileManager.isLinux()) {
deviceInfo.linuxInfo.then((linuxDeviceInfo) {
_loadLinuxParameters(linuxDeviceInfo);
_removeExcludedParameters();
});
} else if (ApplicationProfileManager.isWindows()) {
deviceInfo.windowsInfo.then((windowsInfo) {
_loadWindowsParameters(windowsInfo);
_removeExcludedParameters();
});
} else if (ApplicationProfileManager.isMacOS()) {
deviceInfo.macOsInfo.then((macOsDeviceInfo) {
_loadMacOSParameters(macOsDeviceInfo);
_removeExcludedParameters();
});
} else if (ApplicationProfileManager.isAndroid()) {
deviceInfo.androidInfo.then((androidInfo) {
_loadAndroidParameters(androidInfo);
_removeExcludedParameters();
});
} else if (ApplicationProfileManager.isIos()) {
deviceInfo.iosInfo.then((iosInfo) {
_loadIosParameters(iosInfo);
_removeExcludedParameters();
});
} else {
_logger.info("Couldn't load device info for unsupported device type.");
try {
final deviceInfo = DeviceInfoPlugin();
if (ApplicationProfileManager.isWeb()) {
deviceInfo.webBrowserInfo.then((webBrowserInfo) {
_loadWebParameters(webBrowserInfo);
_removeExcludedParameters();
});
} else if (ApplicationProfileManager.isLinux()) {
deviceInfo.linuxInfo.then((linuxDeviceInfo) {
_loadLinuxParameters(linuxDeviceInfo);
_removeExcludedParameters();
});
} else if (ApplicationProfileManager.isWindows()) {
deviceInfo.windowsInfo.then((windowsInfo) {
_loadWindowsParameters(windowsInfo);
_removeExcludedParameters();
});
} else if (ApplicationProfileManager.isMacOS()) {
deviceInfo.macOsInfo.then((macOsDeviceInfo) {
_loadMacOSParameters(macOsDeviceInfo);
_removeExcludedParameters();
});
} else if (ApplicationProfileManager.isAndroid()) {
deviceInfo.androidInfo.then((androidInfo) {
_loadAndroidParameters(androidInfo);
_removeExcludedParameters();
});
} else if (ApplicationProfileManager.isIos()) {
deviceInfo.iosInfo.then((iosInfo) {
_loadIosParameters(iosInfo);
_removeExcludedParameters();
});
} else {
_logger.info("Couldn't load device info for unsupported device type.");
}
} catch (exception) {
_logger.warning("Couldn't load device info due to error: $exception");
}
}

Expand Down Expand Up @@ -410,15 +414,20 @@ class Catcher2 implements ReportModeAction {
}

void _loadApplicationInfo() {
_applicationParameters['environment'] =
describeEnum(ApplicationProfileManager.getApplicationProfile());

PackageInfo.fromPlatform().then((packageInfo) {
_applicationParameters['version'] = packageInfo.version;
_applicationParameters['appName'] = packageInfo.appName;
_applicationParameters['buildNumber'] = packageInfo.buildNumber;
_applicationParameters['packageName'] = packageInfo.packageName;
});
try {
_applicationParameters['environment'] =
describeEnum(ApplicationProfileManager.getApplicationProfile());

PackageInfo.fromPlatform().then((packageInfo) {
_applicationParameters['version'] = packageInfo.version;
_applicationParameters['appName'] = packageInfo.appName;
_applicationParameters['buildNumber'] = packageInfo.buildNumber;
_applicationParameters['packageName'] = packageInfo.packageName;
});
} catch (exception) {
_logger
.warning("Couldn't load application info due to error: $exception");
}
}

/// We need to setup localizations lazily because context needed to setup
Expand Down

0 comments on commit 9eb615e

Please sign in to comment.