Skip to content

Commit

Permalink
Add error boundaries for corrupted files
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Jan 9, 2025
1 parent 6a33906 commit 037f60d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 25 deletions.
54 changes: 39 additions & 15 deletions api/lib/src/models/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,13 @@ final class NoteData extends ArchiveData<NoteData> {
if (data == null) {
return null;
}
final content = utf8.decode(data);
final json = jsonDecode(content) as Map<String, dynamic>;
return DocumentPage.fromJson(json);
try {
final content = utf8.decode(data);
final json = jsonDecode(content) as Map<String, dynamic>;
return DocumentPage.fromJson(json);
} catch (e) {
return null;
}
}

@useResult
Expand Down Expand Up @@ -280,8 +284,12 @@ final class NoteData extends ArchiveData<NoteData> {
return null;
}
final content = utf8.decode(data);
final json = jsonDecode(content) as Map<String, dynamic>;
return DocumentInfo.fromJson(json);
try {
final json = jsonDecode(content) as Map<String, dynamic>;
return DocumentInfo.fromJson(json);
} catch (e) {
return null;
}
}

@useResult
Expand All @@ -303,7 +311,11 @@ final class NoteData extends ArchiveData<NoteData> {
if (data == null) {
return null;
}
return NoteData.fromData(data);
try {
return NoteData.fromData(data);
} catch (e) {
return null;
}
}

@useResult
Expand Down Expand Up @@ -333,9 +345,13 @@ final class NoteData extends ArchiveData<NoteData> {
if (data == null) {
return null;
}
final content = utf8.decode(data);
final json = jsonDecode(content) as Map<String, dynamic>;
return ButterflyComponent.fromJson(json);
try {
final content = utf8.decode(data);
final json = jsonDecode(content) as Map<String, dynamic>;
return ButterflyComponent.fromJson(json);
} catch (e) {
return null;
}
}

@useResult
Expand All @@ -356,9 +372,13 @@ final class NoteData extends ArchiveData<NoteData> {
if (data == null) {
return null;
}
final content = utf8.decode(data);
final json = jsonDecode(content) as Map<String, dynamic>;
return TextStyleSheet.fromJson(json);
try {
final content = utf8.decode(data);
final json = jsonDecode(content) as Map<String, dynamic>;
return TextStyleSheet.fromJson(json);
} catch (e) {
return null;
}
}

@useResult
Expand Down Expand Up @@ -392,9 +412,13 @@ final class NoteData extends ArchiveData<NoteData> {
if (data == null) {
return null;
}
final content = utf8.decode(data);
final json = jsonDecode(content) as Map<String, dynamic>;
return ColorPalette.fromJson(json);
try {
final content = utf8.decode(data);
final json = jsonDecode(content) as Map<String, dynamic>;
return ColorPalette.fromJson(json);
} catch (e) {
return null;
}
}

@useResult
Expand Down
20 changes: 10 additions & 10 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ packages:
dependency: transitive
description:
name: camera_android_camerax
sha256: abcfa1ac32bd03116b4cfda7e8223ab391f01966e65823c064afe388550d1b3d
sha256: ecadc214daed34d8503540525d26577731c066f1993c254aa5272da7629e8f10
url: "https://pub.dev"
source: hosted
version: "0.6.10+3"
version: "0.6.12"
camera_avfoundation:
dependency: transitive
description:
Expand All @@ -193,10 +193,10 @@ packages:
dependency: transitive
description:
name: camera_platform_interface
sha256: b3ede1f171532e0d83111fe0980b46d17f1aa9788a07a2fbed07366bbdbb9061
sha256: "953e7baed3a7c8fae92f7200afeb2be503ff1a17c3b4e4ed7b76f008c2810a31"
url: "https://pub.dev"
source: hosted
version: "2.8.0"
version: "2.9.0"
camera_web:
dependency: transitive
description:
Expand Down Expand Up @@ -570,10 +570,10 @@ packages:
dependency: "direct main"
description:
name: flutter_svg
sha256: "54900a1a1243f3c4a5506d853a2b5c2dbc38d5f27e52a52618a8054401431123"
sha256: c200fd79c918a40c5cd50ea0877fa13f81bdaf6f0a5d3dbcc2a13e3285d6aa1b
url: "https://pub.dev"
source: hosted
version: "2.0.16"
version: "2.0.17"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -1120,10 +1120,10 @@ packages:
dependency: transitive
description:
name: pubspec_parse
sha256: "81876843eb50dc2e1e5b151792c9a985c5ed2536914115ed04e9c8528f6647b0"
sha256: "0560ba233314abbed0a48a2956f7f022cce7c3e1e73df540277da7544cad4082"
url: "https://pub.dev"
source: hosted
version: "1.4.0"
version: "1.5.0"
qr:
dependency: transitive
description:
Expand Down Expand Up @@ -1518,10 +1518,10 @@ packages:
dependency: transitive
description:
name: vector_graphics_codec
sha256: "2430b973a4ca3c4dbc9999b62b8c719a160100dcbae5c819bae0cacce32c9cdb"
sha256: "99fd9fbd34d9f9a32efd7b6a6aae14125d8237b10403b422a6a6dfeac2806146"
url: "https://pub.dev"
source: hosted
version: "1.1.12"
version: "1.1.13"
vector_graphics_compiler:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions metadata/en-US/changelogs/128.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
This is a hotfix update, cherry picking some important fixes from the last 2.3.0-beta.0 nightly release.

* Add error boundaries for corrupted files
* Fix default stroke width ([#779](https://github.com/LinwoodDev/Butterfly/issues/779))
* Fix svg export shows wrong initial preset
* Fix capture thumbnail uses wrong position
Expand Down

0 comments on commit 037f60d

Please sign in to comment.