Git: Call Firebase.logException on exceptions

We want to Git layer to always work. And ideally these exceptions should
never occur.
This commit is contained in:
Vishesh Handa
2019-08-21 08:37:56 +02:00
parent 8bc9ac9170
commit 7c79c328bd
3 changed files with 25 additions and 14 deletions

View File

@ -114,7 +114,7 @@ linter:
# - unnecessary_overrides # https://github.com/dart-lang/linter/issues/626 and https://github.com/dart-lang/linter/issues/627 # - unnecessary_overrides # https://github.com/dart-lang/linter/issues/626 and https://github.com/dart-lang/linter/issues/627
- unnecessary_statements - unnecessary_statements
- unnecessary_this - unnecessary_this
- use_rethrow_when_possible # - use_rethrow_when_possible
# - use_setters_to_change_properties # not yet tested # - use_setters_to_change_properties # not yet tested
# - use_string_buffers # https://github.com/dart-lang/linter/pull/664 # - use_string_buffers # https://github.com/dart-lang/linter/pull/664
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review

View File

@ -5,13 +5,24 @@ import 'package:fimber/fimber.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_crashlytics/flutter_crashlytics.dart';
const _platform = const MethodChannel('gitjournal.io/git'); const _platform = const MethodChannel('gitjournal.io/git');
Future invokePlatformMethod(String method, [dynamic arguments]) async {
try {
return await _platform.invokeMethod(method, arguments);
} on PlatformException catch (e, stacktrace) {
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 _platform.invokeMethod('getBaseDirectory'); final String path = await invokePlatformMethod('getBaseDirectory');
if (path == null) { if (path == null) {
return null; return null;
} }
@ -31,7 +42,7 @@ class GitRepo {
static Future<void> clone(String folderName, String cloneUrl) async { static Future<void> clone(String folderName, String cloneUrl) async {
try { try {
await _platform.invokeMethod('gitClone', { await invokePlatformMethod('gitClone', {
'cloneUrl': cloneUrl, 'cloneUrl': cloneUrl,
'folderName': folderName, 'folderName': folderName,
}); });
@ -44,7 +55,7 @@ class GitRepo {
static Future<void> init(String folderName) async { static Future<void> init(String folderName) async {
try { try {
await _platform.invokeMethod('gitInit', { await invokePlatformMethod('gitInit', {
'folderName': folderName, 'folderName': folderName,
}); });
} on PlatformException catch (e) { } on PlatformException catch (e) {
@ -55,7 +66,7 @@ class GitRepo {
Future<void> pull() async { Future<void> pull() async {
try { try {
await _platform.invokeMethod('gitPull', { await invokePlatformMethod('gitPull', {
'folderName': folderName, 'folderName': folderName,
'authorName': authorName, 'authorName': authorName,
'authorEmail': authorEmail, 'authorEmail': authorEmail,
@ -69,7 +80,7 @@ class GitRepo {
Future<void> add(String filePattern) async { Future<void> add(String filePattern) async {
try { try {
await _platform.invokeMethod('gitAdd', { await invokePlatformMethod('gitAdd', {
'folderName': folderName, 'folderName': folderName,
'filePattern': filePattern, 'filePattern': filePattern,
}); });
@ -80,7 +91,7 @@ class GitRepo {
Future<void> rm(String filePattern) async { Future<void> rm(String filePattern) async {
try { try {
await _platform.invokeMethod('gitRm', { await invokePlatformMethod('gitRm', {
'folderName': folderName, 'folderName': folderName,
'filePattern': filePattern, 'filePattern': filePattern,
}); });
@ -91,7 +102,7 @@ class GitRepo {
Future<void> push() async { Future<void> push() async {
try { try {
await _platform.invokeMethod('gitPush', { await invokePlatformMethod('gitPush', {
'folderName': folderName, 'folderName': folderName,
}); });
} on PlatformException catch (e) { } on PlatformException catch (e) {
@ -103,7 +114,7 @@ class GitRepo {
// FIXME: Change this method to just resetHard // FIXME: Change this method to just resetHard
Future<void> resetLast() async { Future<void> resetLast() async {
try { try {
await _platform.invokeMethod('gitResetLast', { await invokePlatformMethod('gitResetLast', {
'folderName': folderName, 'folderName': folderName,
}); });
} on PlatformException catch (e) { } on PlatformException catch (e) {
@ -116,7 +127,7 @@ class GitRepo {
// FIXME: Actually implement the 'when' // FIXME: Actually implement the 'when'
Future<void> commit({@required String message, String when}) async { Future<void> commit({@required String message, String when}) async {
try { try {
await _platform.invokeMethod('gitCommit', { await invokePlatformMethod('gitCommit', {
'folderName': folderName, 'folderName': folderName,
'authorName': authorName, 'authorName': authorName,
'authorEmail': authorEmail, 'authorEmail': authorEmail,
@ -132,7 +143,7 @@ class GitRepo {
Future<String> generateSSHKeys({@required String comment}) async { Future<String> generateSSHKeys({@required String comment}) async {
Fimber.d("generateSSHKeyss: " + comment); Fimber.d("generateSSHKeyss: " + comment);
try { try {
String publicKey = await _platform.invokeMethod('generateSSHKeys', { String publicKey = await invokePlatformMethod('generateSSHKeys', {
'comment': comment, 'comment': comment,
}); });
Fimber.d("Public Key " + publicKey); Fimber.d("Public Key " + publicKey);
@ -142,7 +153,7 @@ Future<String> generateSSHKeys({@required String comment}) async {
} }
try { try {
String publicKey = await _platform.invokeMethod('getSSHPublicKey'); String publicKey = await invokePlatformMethod('getSSHPublicKey');
Fimber.d("Public Key " + publicKey); Fimber.d("Public Key " + publicKey);
return publicKey; return publicKey;
} on PlatformException catch (e) { } on PlatformException catch (e) {
@ -158,7 +169,7 @@ Future<void> setSshKeys({
}) async { }) async {
Fimber.d("setSshKeys"); Fimber.d("setSshKeys");
try { try {
await _platform.invokeMethod('setSshKeys', { await invokePlatformMethod('setSshKeys', {
'publicKey': publicKey, 'publicKey': publicKey,
'privateKey': privateKey, 'privateKey': privateKey,
}); });

View File

@ -1,6 +1,6 @@
name: journal name: journal
description: A Journaling App Built on top of Git description: A Journaling App Built on top of Git
version: 1.1.11+10 version: 1.1.12+10
dependencies: dependencies:
flutter: flutter: