mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 03:59:23 +00:00
Save exceptions locally
This commit is contained in:
parent
38da6e73d4
commit
68c20641b9
1 changed files with 31 additions and 4 deletions
|
@ -1,4 +1,7 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'dart:isolate';
|
||||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||||
import 'package:cake_wallet/entities/language_service.dart';
|
import 'package:cake_wallet/entities/language_service.dart';
|
||||||
import 'package:cake_wallet/buy/order.dart';
|
import 'package:cake_wallet/buy/order.dart';
|
||||||
|
@ -46,11 +49,24 @@ Future<void> main() async {
|
||||||
await runZonedGuarded(() async {
|
await runZonedGuarded(() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
// FlutterError.onError = ;
|
FlutterError.onError = (errorDetails) {
|
||||||
|
_saveException(errorDetails.exception.toString(), errorDetails.stack);
|
||||||
|
};
|
||||||
|
|
||||||
// Isolate.current.addErrorListener(RawReceivePort((pair) async {
|
PlatformDispatcher.instance.onError = (error, stack) {
|
||||||
// final List<dynamic> errorAndStacktrace = pair;
|
_saveException(error.toString(), stack);
|
||||||
// }).sendPort);
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
Isolate.current.addErrorListener(RawReceivePort((pair) async {
|
||||||
|
final errorAndStacktrace = pair as List<String?>;
|
||||||
|
_saveException(
|
||||||
|
errorAndStacktrace.first,
|
||||||
|
errorAndStacktrace.last == null
|
||||||
|
? null
|
||||||
|
: StackTrace.fromString(errorAndStacktrace.last!),
|
||||||
|
);
|
||||||
|
}).sendPort);
|
||||||
|
|
||||||
final appDir = await getApplicationDocumentsDirectory();
|
final appDir = await getApplicationDocumentsDirectory();
|
||||||
await Hive.close();
|
await Hive.close();
|
||||||
|
@ -151,6 +167,17 @@ Future<void> main() async {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _saveException(String? error, StackTrace? stackTrace) async {
|
||||||
|
final file = File('/error.txt');
|
||||||
|
final exception = {
|
||||||
|
"${DateTime.now()}": {
|
||||||
|
"error": error,
|
||||||
|
"stackTrace": stackTrace.toString(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
await file.writeAsString(jsonEncode(exception), mode: FileMode.append);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> initialSetup(
|
Future<void> initialSetup(
|
||||||
{required SharedPreferences sharedPreferences,
|
{required SharedPreferences sharedPreferences,
|
||||||
required Box<Node> nodes,
|
required Box<Node> nodes,
|
||||||
|
|
Loading…
Reference in a new issue