1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

LibPDF: Propagate errors in Parser and Document

This commit is contained in:
Matthew Olsson 2022-03-05 17:30:55 -07:00 committed by Andreas Kling
parent 7e1c823725
commit 73cf8205b4
16 changed files with 472 additions and 420 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org>
* Copyright (c) 2021-2022, Matthew Olsson <mattco@serenityos.org>
* Copyright (c) 2021, Mustafa Quraish <mustafa@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -151,12 +151,15 @@ void PDFViewerWidget::open_file(Core::File& file)
window()->set_title(String::formatted("{} - PDF Viewer", file.filename()));
m_buffer = file.read_all();
auto document = PDF::Document::create(m_buffer);
if (!document) {
GUI::MessageBox::show_error(nullptr, String::formatted("Couldn't load PDF: {}", file.filename()));
auto maybe_document = PDF::Document::create(m_buffer);
if (maybe_document.is_error()) {
auto error = maybe_document.release_error();
GUI::MessageBox::show_error(nullptr, String::formatted("Couldn't load PDF {}:\n{}", file.filename(), error.message()));
return;
}
auto document = maybe_document.release_value();
m_viewer->set_document(document);
m_total_page_label->set_text(String::formatted("of {}", document->get_page_count()));