summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-07 00:37:07 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-08 00:35:27 +0100
commit0f5477c721c4cd8f1dbbf34eafd348bd248a1f79 (patch)
tree08faa88b1f4ac94d5d75f9914942fa37524e3417 /Userland/Applications
parentc837bd551e7e37860d2b61c5dbcd393120619178 (diff)
downloadserenity-0f5477c721c4cd8f1dbbf34eafd348bd248a1f79.zip
AK: Use ErrorOr<T> for MappedFile factories
Replace Result<T, E> with ErrorOr<T> and propagate the error to callers.
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/Help/ManualModel.cpp11
-rw-r--r--Userland/Applications/Help/ManualModel.h2
-rw-r--r--Userland/Applications/Help/main.cpp2
-rw-r--r--Userland/Applications/PixelPaint/ProjectLoader.cpp2
4 files changed, 8 insertions, 9 deletions
diff --git a/Userland/Applications/Help/ManualModel.cpp b/Userland/Applications/Help/ManualModel.cpp
index 353502cd49..8461788b56 100644
--- a/Userland/Applications/Help/ManualModel.cpp
+++ b/Userland/Applications/Help/ManualModel.cpp
@@ -9,6 +9,7 @@
#include "ManualPageNode.h"
#include "ManualSectionNode.h"
#include <AK/ByteBuffer.h>
+#include <AK/Try.h>
#include <LibCore/File.h>
#include <LibGUI/FilteringProxyModel.h>
@@ -59,7 +60,7 @@ String ManualModel::page_path(const GUI::ModelIndex& index) const
return page->path();
}
-Result<StringView, OSError> ManualModel::page_view(const String& path) const
+ErrorOr<StringView> ManualModel::page_view(String const& path) const
{
if (path.is_empty())
return StringView {};
@@ -71,12 +72,10 @@ Result<StringView, OSError> ManualModel::page_view(const String& path) const
return StringView { mapped_file.value()->bytes() };
}
- auto file_or_error = MappedFile::map(path);
- if (file_or_error.is_error())
- return file_or_error.error();
+ auto file = TRY(MappedFile::map(path));
- StringView view { file_or_error.value()->bytes() };
- m_mapped_files.set(path, file_or_error.release_value());
+ StringView view { file->bytes() };
+ m_mapped_files.set(path, move(file));
return view;
}
diff --git a/Userland/Applications/Help/ManualModel.h b/Userland/Applications/Help/ManualModel.h
index 9c2002f15f..1345fb0548 100644
--- a/Userland/Applications/Help/ManualModel.h
+++ b/Userland/Applications/Help/ManualModel.h
@@ -25,7 +25,7 @@ public:
String page_path(const GUI::ModelIndex&) const;
String page_and_section(const GUI::ModelIndex&) const;
- Result<StringView, OSError> page_view(const String& path) const;
+ ErrorOr<StringView> page_view(String const& path) const;
void update_section_node_on_toggle(const GUI::ModelIndex&, const bool);
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
diff --git a/Userland/Applications/Help/main.cpp b/Userland/Applications/Help/main.cpp
index f7b7be2092..7ecac91743 100644
--- a/Userland/Applications/Help/main.cpp
+++ b/Userland/Applications/Help/main.cpp
@@ -139,7 +139,7 @@ int main(int argc, char* argv[])
auto source_result = model->page_view(path);
if (source_result.is_error()) {
- GUI::MessageBox::show(window, source_result.error().string(), "Failed to open man page", GUI::MessageBox::Type::Error);
+ GUI::MessageBox::show(window, String::formatted("{}", source_result.error()), "Failed to open man page", GUI::MessageBox::Type::Error);
return;
}
diff --git a/Userland/Applications/PixelPaint/ProjectLoader.cpp b/Userland/Applications/PixelPaint/ProjectLoader.cpp
index a6c703fe7e..df48b2747a 100644
--- a/Userland/Applications/PixelPaint/ProjectLoader.cpp
+++ b/Userland/Applications/PixelPaint/ProjectLoader.cpp
@@ -31,7 +31,7 @@ Result<void, String> ProjectLoader::try_load_from_fd_and_close(int fd, StringVie
auto file_or_error = MappedFile::map_from_fd_and_close(fd, path);
if (file_or_error.is_error())
- return String::formatted("Unable to mmap file {}", file_or_error.error().string());
+ return String::formatted("Unable to mmap file {}", file_or_error.error());
auto& mapped_file = *file_or_error.value();
// FIXME: Find a way to avoid the memory copy here.