mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-03-11 17:25:32 +00:00
Add global error handling in main function
This commit is contained in:
parent
1256e608c7
commit
a5fd40fdfb
1 changed files with 55 additions and 25 deletions
|
|
@ -54,6 +54,28 @@ String? customDns;
|
|||
void main(List<String> args) async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
if (Platform.isLinux && runWebViewTitleBarWidget(args)) return;
|
||||
|
||||
// Widget-layer errors (build / layout / paint)
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
FlutterError.presentError(details); // keep default red-screen in debug
|
||||
AppLogger.log(
|
||||
'FlutterError: ${details.exceptionAsString()}\n${details.stack}',
|
||||
logLevel: LogLevel.error,
|
||||
);
|
||||
};
|
||||
|
||||
// Async errors that escape the Flutter framework (PlatformDispatcher)
|
||||
PlatformDispatcher.instance.onError = (Object error, StackTrace stack) {
|
||||
AppLogger.log(
|
||||
'PlatformDispatcher error: $error\n$stack',
|
||||
logLevel: LogLevel.error,
|
||||
);
|
||||
return true; // handled — prevent app termination
|
||||
};
|
||||
|
||||
// Zone-level catch-all for anything that slips through both layers
|
||||
runZonedGuarded(
|
||||
() async {
|
||||
MediaKit.ensureInitialized();
|
||||
await RustLib.init();
|
||||
await imgCropIsolate.start();
|
||||
|
|
@ -79,7 +101,15 @@ void main(List<String> args) async {
|
|||
await storage.requestPermission();
|
||||
isar = await storage.initDB(null, inspector: kDebugMode);
|
||||
runApp(ProviderScope(child: MyApp(), retry: (retryCount, error) => null));
|
||||
unawaited(_postLaunchInit(storage)); // Defer non-essential async operations
|
||||
unawaited(_postLaunchInit(storage));
|
||||
},
|
||||
(Object error, StackTrace stack) {
|
||||
AppLogger.log(
|
||||
'runZonedGuarded error: $error\n$stack',
|
||||
logLevel: LogLevel.error,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _postLaunchInit(StorageProvider storage) async {
|
||||
|
|
|
|||
Loading…
Reference in a new issue