From 689b3c2c264402e5901b1dc7a41ec19209f67164 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sat, 14 Jan 2023 22:11:56 -0500 Subject: [PATCH] HexEditor: Propagate errors from `HexDocumentFile::set_title()` --- Userland/Applications/HexEditor/HexDocument.cpp | 7 ++++--- Userland/Applications/HexEditor/HexDocument.h | 2 +- Userland/Applications/HexEditor/HexEditor.cpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Userland/Applications/HexEditor/HexDocument.cpp b/Userland/Applications/HexEditor/HexDocument.cpp index 2ce1677a6e..ce98bc65af 100644 --- a/Userland/Applications/HexEditor/HexDocument.cpp +++ b/Userland/Applications/HexEditor/HexDocument.cpp @@ -73,7 +73,7 @@ ErrorOr> HexDocumentFile::create(NonnullOwnPtrset_file(move(document->m_file)); + TRY(document->set_file(move(document->m_file))); return document; } @@ -150,7 +150,7 @@ void HexDocumentFile::clear_changes() m_changes.clear(); } -void HexDocumentFile::set_file(NonnullOwnPtr file) +ErrorOr HexDocumentFile::set_file(NonnullOwnPtr file) { m_file = move(file); @@ -159,11 +159,12 @@ void HexDocumentFile::set_file(NonnullOwnPtr file) else m_file_size = result.value(); - m_file->seek(0, SeekMode::SetPosition).release_value_but_fixme_should_propagate_errors(); + TRY(m_file->seek(0, SeekMode::SetPosition)); clear_changes(); // make sure the next get operation triggers a read m_buffer_file_pos = m_file_size + 1; + return {}; } NonnullOwnPtr const& HexDocumentFile::file() const diff --git a/Userland/Applications/HexEditor/HexDocument.h b/Userland/Applications/HexEditor/HexDocument.h index 92c5f7ca09..3f19b8f3e6 100644 --- a/Userland/Applications/HexEditor/HexDocument.h +++ b/Userland/Applications/HexEditor/HexDocument.h @@ -64,7 +64,7 @@ public: HexDocumentFile(HexDocumentFile&&) = default; HexDocumentFile(HexDocumentFile const&) = delete; - void set_file(NonnullOwnPtr file); + ErrorOr set_file(NonnullOwnPtr file); NonnullOwnPtr const& file() const; ErrorOr write_to_file(); ErrorOr write_to_file(Core::Stream::File& file); diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp index 623f33c242..e3c28811db 100644 --- a/Userland/Applications/HexEditor/HexEditor.cpp +++ b/Userland/Applications/HexEditor/HexEditor.cpp @@ -141,7 +141,7 @@ ErrorOr HexEditor::save_as(NonnullOwnPtr new_file) if (m_document->type() == HexDocument::Type::File) { auto& file_document = static_cast(*m_document); TRY(file_document.write_to_file(*new_file)); - file_document.set_file(move(new_file)); + TRY(file_document.set_file(move(new_file))); } else { auto& memory_document = static_cast(*m_document); TRY(memory_document.write_to_file(*new_file));