|
|
|
@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter_highlighter/flutter_highlighter.dart';
|
|
|
|
|
import 'package:flutter_highlighter/themes/shades-of-purple.dart';
|
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
|
import 'package:path/path.dart' as path;
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
@ -20,6 +21,14 @@ class ErrorReporter {
|
|
|
|
|
|
|
|
|
|
const ErrorReporter(this.context, [this.message]);
|
|
|
|
|
|
|
|
|
|
static const Set<Type> ingoredTypes = {
|
|
|
|
|
IOException,
|
|
|
|
|
http.ClientException,
|
|
|
|
|
SocketException,
|
|
|
|
|
TlsException,
|
|
|
|
|
HandshakeException,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Future<File> _getTemporaryErrorLogFile() async {
|
|
|
|
|
final tempDir = await getTemporaryDirectory();
|
|
|
|
|
return File(path.join(tempDir.path, 'error_log.txt'));
|
|
|
|
@ -29,6 +38,7 @@ class ErrorReporter {
|
|
|
|
|
Object error, [
|
|
|
|
|
StackTrace? stackTrace,
|
|
|
|
|
]) async {
|
|
|
|
|
if (ingoredTypes.contains(error.runtimeType)) return;
|
|
|
|
|
final file = await _getTemporaryErrorLogFile();
|
|
|
|
|
if (await file.exists()) await file.delete();
|
|
|
|
|
await file.writeAsString(
|
|
|
|
@ -40,11 +50,12 @@ class ErrorReporter {
|
|
|
|
|
final file = await _getTemporaryErrorLogFile();
|
|
|
|
|
if (!(await file.exists())) return;
|
|
|
|
|
final content = await file.readAsString();
|
|
|
|
|
|
|
|
|
|
_onErrorCallback(content);
|
|
|
|
|
await file.delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onErrorCallback(Object error, [StackTrace? stackTrace]) {
|
|
|
|
|
if (ingoredTypes.contains(error.runtimeType)) return;
|
|
|
|
|
Logs().e(message ?? 'Error caught', error, stackTrace);
|
|
|
|
|
final text = '$error\n${stackTrace ?? ''}';
|
|
|
|
|
return _onErrorCallback(text);
|
|
|
|
|