mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
Log git exceptions in Crashlytics
This commit is contained in:
@ -3,52 +3,13 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
import 'package:flutter_crashlytics/flutter_crashlytics.dart';
|
|
||||||
|
|
||||||
const _platform = MethodChannel('gitjournal.io/git');
|
const _platform = MethodChannel('gitjournal.io/git');
|
||||||
|
|
||||||
bool shouldIgnorePlatformException(PlatformException ex) {
|
|
||||||
var msg = ex.message.toLowerCase();
|
|
||||||
if (msg.contains("failed to resolve address for")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (msg.contains("failed to connect to")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (msg.contains("no address associated with hostname")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (msg.contains("failed to connect to")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (msg.contains("unauthorized")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (msg.contains("invalid credentials")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (msg.contains("failed to start ssh session")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future invokePlatformMethod(String method, [dynamic arguments]) async {
|
|
||||||
try {
|
|
||||||
return await _platform.invokeMethod(method, arguments);
|
|
||||||
} on PlatformException catch (e, stacktrace) {
|
|
||||||
if (!shouldIgnorePlatformException(e)) {
|
|
||||||
await FlutterCrashlytics().logException(e, stacktrace);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// This gives us the directory where all the git repos will be stored
|
/// This gives us the directory where all the git repos will be stored
|
||||||
///
|
///
|
||||||
Future<Directory> getGitBaseDirectory() async {
|
Future<Directory> getGitBaseDirectory() async {
|
||||||
final String path = await invokePlatformMethod('getBaseDirectory');
|
final String path = await _platform.invokeMethod('getBaseDirectory');
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:fimber/fimber.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter_crashlytics/flutter_crashlytics.dart';
|
||||||
|
|
||||||
import 'package:git_bindings/git_bindings.dart';
|
import 'package:git_bindings/git_bindings.dart';
|
||||||
|
|
||||||
import 'package:gitjournal/core/note.dart';
|
import 'package:gitjournal/core/note.dart';
|
||||||
@ -104,17 +105,48 @@ class GitNoteRepository {
|
|||||||
Future<bool> sync() async {
|
Future<bool> sync() async {
|
||||||
try {
|
try {
|
||||||
await _gitRepo.pull();
|
await _gitRepo.pull();
|
||||||
} on GitException catch (ex) {
|
} on GitException catch (e, stacktrace) {
|
||||||
Fimber.d(ex.toString());
|
if (shouldLogGitException(e)) {
|
||||||
|
await FlutterCrashlytics().logException(e, stacktrace);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await _gitRepo.push();
|
await _gitRepo.push();
|
||||||
} on GitException catch (ex) {
|
} on GitException catch (e, stacktrace) {
|
||||||
Fimber.d(ex.toString());
|
if (shouldLogGitException(e)) {
|
||||||
rethrow;
|
await FlutterCrashlytics().logException(e, stacktrace);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool shouldLogGitException(GitException ex) {
|
||||||
|
var msg = ex.cause.toLowerCase();
|
||||||
|
if (msg.contains("failed to resolve address for")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (msg.contains("failed to connect to")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (msg.contains("no address associated with hostname")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (msg.contains("failed to connect to")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (msg.contains("unauthorized")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (msg.contains("invalid credentials")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (msg.contains("failed to start ssh session")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user