1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:04:59 +00:00

image: Don't just crash when the input file can't be decoded

If the input file didn't exist at all, the TRY(MappedFile::map())
gives us a (cryptic) error message, but if it existed but wasn't an
image file, we would crash. Now we print a message instead.
This commit is contained in:
Nico Weber 2023-03-16 09:21:01 +01:00 committed by Tim Flynn
parent 0591aa1d96
commit 3a7257c9fe

View file

@ -41,6 +41,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto file = TRY(Core::MappedFile::map(in_path));
auto decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(file->bytes());
if (!decoder) {
warnln("Failed to decode input file '{}'", in_path);
return 1;
}
// This uses ImageDecoder instead of Bitmap::load_from_file() to have more control
// over selecting a frame, access color profile data, and so on in the future.