Catch possible exceptions when creating the fileName

This can apparently happen, and we should have a fallback. Additionally
Dart has both an 'Error' and an 'Exception' which are two different
things. This makes no sense.
This commit is contained in:
Vishesh Handa
2020-06-09 18:09:17 +02:00
parent 9cb810f41d
commit 9ba0bc831c
2 changed files with 13 additions and 3 deletions

View File

@ -75,7 +75,13 @@ class Note with NotesNotifier {
String get filePath {
if (_filePath == null) {
_filePath = p.join(parent.folderPath, _buildFileName());
try {
_filePath = p.join(parent.folderPath, _buildFileName());
} catch (e, stackTrace) {
Log.e("_buildFileName: $e");
logExceptionWarning(e, stackTrace);
_filePath = p.join(parent.folderPath, Uuid().v4());
}
switch (_fileFormat) {
case NoteFileFormat.Txt:
if (!_filePath.toLowerCase().endsWith('.txt')) {

View File

@ -100,7 +100,10 @@ Future<void> reportError(Object error, StackTrace stackTrace) async {
print(stackTrace);
}
Future<void> logException(Exception e, StackTrace stackTrace) async {
// Dart makes a distiction between Errors and Exceptions
// so we need to use dynamic
Future<void> logException(Object e, StackTrace stackTrace) async {
assert(e is Exception || e is Error);
if (!reportCrashes) {
return;
}
@ -109,7 +112,8 @@ Future<void> logException(Exception e, StackTrace stackTrace) async {
return FlutterCrashlytics().logException(e, stackTrace);
}
Future<void> logExceptionWarning(Exception e, StackTrace stackTrace) async {
Future<void> logExceptionWarning(Object e, StackTrace stackTrace) async {
assert(e is Exception || e is Error);
if (!reportCrashes) {
return;
}