diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2023-05-18 08:50:38 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-19 06:20:41 +0200 |
commit | 444470b238eb5fa4905d1fa5383931ef84bf6a41 (patch) | |
tree | 3eae27bcaa71ca9af465a75a878a1a58a32a016e /Userland | |
parent | fef594708eec1c1d26b54c26b09e40f1df1ed99c (diff) | |
download | serenity-444470b238eb5fa4905d1fa5383931ef84bf6a41.zip |
Applications: Improve FSAC error message handling
Fixes apps showing redundant error messages and terminating
unnecessarily on failed file requests. It's nicer to drop the
user off at the equivalent of a default document on failure if
possible.
Also fixes TextEditor not showing response errors for missing files
in the recently opened list.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Applications/FontEditor/main.cpp | 15 | ||||
-rw-r--r-- | Userland/Applications/HexEditor/main.cpp | 5 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/main.cpp | 7 | ||||
-rw-r--r-- | Userland/Applications/TextEditor/main.cpp | 5 | ||||
-rw-r--r-- | Userland/Applications/ThemeEditor/main.cpp | 4 |
5 files changed, 17 insertions, 19 deletions
diff --git a/Userland/Applications/FontEditor/main.cpp b/Userland/Applications/FontEditor/main.cpp index f19e035ece..37eec854b0 100644 --- a/Userland/Applications/FontEditor/main.cpp +++ b/Userland/Applications/FontEditor/main.cpp @@ -59,14 +59,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) auto default_path = TRY(String::from_deprecated_string(Config::read_string("FontEditor"sv, "Defaults"sv, "Font"sv, {}))); auto path_to_load = path.is_empty() ? default_path : path; - auto open_or_error = [&]() -> ErrorOr<void> { - if (path_to_load.is_empty()) - return {}; - auto file = TRY(FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path_to_load)); - return TRY(font_editor->open_file(path, file.release_stream())); - }(); - if (open_or_error.is_error()) - font_editor->show_error(open_or_error.release_error(), "Opening"sv, path_to_load); + if (!path_to_load.is_empty()) { + auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path_to_load); + if (!response.is_error()) { + if (auto result = font_editor->open_file(path, response.value().release_stream()); result.is_error()) + font_editor->show_error(result.release_error(), "Opening"sv, path_to_load); + } + } return app->exec(); } diff --git a/Userland/Applications/HexEditor/main.cpp b/Userland/Applications/HexEditor/main.cpp index bfe6cc3df2..29d9cb8bd9 100644 --- a/Userland/Applications/HexEditor/main.cpp +++ b/Userland/Applications/HexEditor/main.cpp @@ -55,9 +55,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) if (arguments.argc > 1) { // FIXME: Using `try_request_file_read_only_approved` doesn't work here since the file stored in the editor is only readable. auto response = FileSystemAccessClient::Client::the().request_file(window, arguments.strings[1], Core::File::OpenMode::ReadWrite); - if (response.is_error()) - return 1; - hex_editor_widget->open_file(response.value().filename(), response.value().release_stream()); + if (!response.is_error()) + hex_editor_widget->open_file(response.value().filename(), response.value().release_stream()); } return app->exec(); diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp index cc359811a2..5761937e1f 100644 --- a/Userland/Applications/PixelPaint/main.cpp +++ b/Userland/Applications/PixelPaint/main.cpp @@ -75,9 +75,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) if (!image_file.is_empty()) { auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, image_file); - if (response.is_error()) - return 1; - main_widget->open_image(response.release_value()); + if (!response.is_error()) + main_widget->open_image(response.release_value()); + else + TRY(main_widget->create_default_image()); } else { TRY(main_widget->create_default_image()); } diff --git a/Userland/Applications/TextEditor/main.cpp b/Userland/Applications/TextEditor/main.cpp index a6b6e09c82..11cab94012 100644 --- a/Userland/Applications/TextEditor/main.cpp +++ b/Userland/Applications/TextEditor/main.cpp @@ -76,19 +76,20 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) if (!file_to_edit.is_empty()) { auto filename = TRY(String::from_utf8(file_to_edit)); FileArgument parsed_argument(filename); + + FileSystemAccessClient::Client::the().set_silence_errors(FileSystemAccessClient::ErrorFlag::NoEntries); auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, parsed_argument.filename().to_deprecated_string()); if (response.is_error()) { if (response.error().code() == ENOENT) text_widget->open_nonexistent_file(parsed_argument.filename().to_deprecated_string()); - else - return 1; } else { TRY(text_widget->read_file(response.value().filename(), response.value().stream())); text_widget->editor().set_cursor_and_focus_line(parsed_argument.line().value_or(1) - 1, parsed_argument.column().value_or(0)); } text_widget->update_title(); + FileSystemAccessClient::Client::the().set_silence_errors(FileSystemAccessClient::ErrorFlag::None); } text_widget->update_statusbar(); diff --git a/Userland/Applications/ThemeEditor/main.cpp b/Userland/Applications/ThemeEditor/main.cpp index c2185644b4..63ea7b39d4 100644 --- a/Userland/Applications/ThemeEditor/main.cpp +++ b/Userland/Applications/ThemeEditor/main.cpp @@ -53,9 +53,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) app->event_loop().deferred_invoke( [&window, &path, &main_widget]() { auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path.value().to_deprecated_string()); - if (response.is_error()) - GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error())); - else { + if (!response.is_error()) { auto load_from_file_result = main_widget->load_from_file(response.value().filename(), response.value().release_stream()); if (load_from_file_result.is_error()) GUI::MessageBox::show_error(window, DeprecatedString::formatted("Loading theme from file has failed: {}", load_from_file_result.error())); |