mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:37:46 +00:00
Userland: Propagate errors from file detail providers in file utility
They already return ErrorOr<T>, so we can just use TRY() instead of manually checking for errors.
This commit is contained in:
parent
e56098f734
commit
94bcb5bea8
1 changed files with 7 additions and 18 deletions
|
@ -29,13 +29,9 @@ static ErrorOr<Optional<String>> description_only(StringView description, String
|
||||||
// FIXME: Ideally Gfx::ImageDecoder could tell us the image type directly.
|
// FIXME: Ideally Gfx::ImageDecoder could tell us the image type directly.
|
||||||
static ErrorOr<Optional<String>> image_details(StringView description, StringView path)
|
static ErrorOr<Optional<String>> image_details(StringView description, StringView path)
|
||||||
{
|
{
|
||||||
auto file_or_error = Core::MappedFile::map(path);
|
auto mapped_file = TRY(Core::MappedFile::map(path));
|
||||||
if (file_or_error.is_error())
|
|
||||||
return OptionalNone {};
|
|
||||||
|
|
||||||
auto& mapped_file = *file_or_error.value();
|
|
||||||
auto mime_type = Core::guess_mime_type_based_on_filename(path);
|
auto mime_type = Core::guess_mime_type_based_on_filename(path);
|
||||||
auto image_decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(mapped_file.bytes(), mime_type);
|
auto image_decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(mapped_file->bytes(), mime_type);
|
||||||
if (!image_decoder)
|
if (!image_decoder)
|
||||||
return OptionalNone {};
|
return OptionalNone {};
|
||||||
|
|
||||||
|
@ -97,15 +93,11 @@ static ErrorOr<Optional<String>> audio_details(StringView description, StringVie
|
||||||
|
|
||||||
static ErrorOr<Optional<String>> gzip_details(StringView description, StringView path)
|
static ErrorOr<Optional<String>> gzip_details(StringView description, StringView path)
|
||||||
{
|
{
|
||||||
auto file_or_error = Core::MappedFile::map(path);
|
auto mapped_file = TRY(Core::MappedFile::map(path));
|
||||||
if (file_or_error.is_error())
|
if (!Compress::GzipDecompressor::is_likely_compressed(mapped_file->bytes()))
|
||||||
return OptionalNone {};
|
return OptionalNone {};
|
||||||
|
|
||||||
auto& mapped_file = *file_or_error.value();
|
auto gzip_details = Compress::GzipDecompressor::describe_header(mapped_file->bytes());
|
||||||
if (!Compress::GzipDecompressor::is_likely_compressed(mapped_file.bytes()))
|
|
||||||
return OptionalNone {};
|
|
||||||
|
|
||||||
auto gzip_details = Compress::GzipDecompressor::describe_header(mapped_file.bytes());
|
|
||||||
if (!gzip_details.has_value())
|
if (!gzip_details.has_value())
|
||||||
return OptionalNone {};
|
return OptionalNone {};
|
||||||
|
|
||||||
|
@ -114,11 +106,8 @@ static ErrorOr<Optional<String>> gzip_details(StringView description, StringView
|
||||||
|
|
||||||
static ErrorOr<Optional<String>> elf_details(StringView description, StringView path)
|
static ErrorOr<Optional<String>> elf_details(StringView description, StringView path)
|
||||||
{
|
{
|
||||||
auto file_or_error = Core::MappedFile::map(path);
|
auto mapped_file = TRY(Core::MappedFile::map(path));
|
||||||
if (file_or_error.is_error())
|
auto elf_data = mapped_file->bytes();
|
||||||
return OptionalNone {};
|
|
||||||
auto& mapped_file = *file_or_error.value();
|
|
||||||
auto elf_data = mapped_file.bytes();
|
|
||||||
ELF::Image elf_image(elf_data);
|
ELF::Image elf_image(elf_data);
|
||||||
if (!elf_image.is_valid())
|
if (!elf_image.is_valid())
|
||||||
return OptionalNone {};
|
return OptionalNone {};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue