Skip to content

Commit a565080

Browse files
committed
catch all exceptions when parsing animation
1 parent 2e2ae46 commit a565080

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

packages/core/lib/generators/integrations/image_integration.dart

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -204,32 +204,39 @@ class AssetGenImageAnimation {
204204
}
205205

206206
ImageAnimation? _parseAnimation(AssetType asset) {
207-
final decoder = switch (asset.mime) {
208-
'image/gif' => img.GifDecoder(),
209-
'image/webp' => img.WebPDecoder(),
210-
_ => null,
211-
};
212-
213-
if (decoder == null) {
214-
return null;
215-
}
207+
try {
208+
final decoder = switch (asset.mime) {
209+
'image/gif' => img.GifDecoder(),
210+
'image/webp' => img.WebPDecoder(),
211+
_ => null,
212+
};
213+
214+
if (decoder == null) {
215+
return null;
216+
}
216217

217-
final file = File(asset.fullPath);
218-
final bytes = file.readAsBytesSync();
219-
final image = decoder.decode(bytes);
218+
final file = File(asset.fullPath);
219+
final bytes = file.readAsBytesSync();
220+
final image = decoder.decode(bytes);
220221

221-
if (image == null) {
222-
return null;
223-
}
222+
if (image == null) {
223+
return null;
224+
}
224225

225-
return ImageAnimation(
226-
frames: image.frames.length,
227-
duration: Duration(
228-
milliseconds: image.frames.fold(
229-
0,
230-
(duration, frame) => duration + frame.frameDuration,
226+
return ImageAnimation(
227+
frames: image.frames.length,
228+
duration: Duration(
229+
milliseconds: image.frames.fold(
230+
0,
231+
(duration, frame) => duration + frame.frameDuration,
232+
),
231233
),
232-
),
233-
);
234+
);
235+
} catch (e) {
236+
stderr.writeln(
237+
'[WARNING] Failed to parse \'${asset.path}\' animation information: $e',
238+
);
239+
}
240+
return null;
234241
}
235242
}

0 commit comments

Comments
 (0)