From e7b70a1435fc391eea248cac0603eabccec2f8a1 Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Mon, 24 May 2021 14:23:08 -0700 Subject: [PATCH] PDFViewer: Display error dialog if necessary instead of crashing --- .../Applications/PDFViewer/PDFViewerWidget.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp index c02d5fae89..7f7b0c7f4d 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -103,11 +104,18 @@ void PDFViewerWidget::open_file(const String& path) { window()->set_title(String::formatted("{} - PDF Viewer", path)); auto file_result = Core::File::open(path, Core::OpenMode::ReadOnly); - VERIFY(!file_result.is_error()); + if (file_result.is_error()) { + GUI::MessageBox::show_error(nullptr, String::formatted("Couldn't open file: {}", path)); + return; + } + m_buffer = file_result.value()->read_all(); auto document = PDF::Document::create(m_buffer); - // FIXME: Show error dialog if the Document is invalid - VERIFY(document); + if (!document) { + GUI::MessageBox::show_error(nullptr, String::formatted("Couldn't load PDF: {}", path)); + return; + } + m_viewer->set_document(document); m_total_page_label->set_text(String::formatted("of {}", document->get_page_count())); m_total_page_label->set_fixed_width(30);