diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-02-06 13:33:42 +0000 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2022-02-16 19:49:41 -0500 |
commit | 8260135d4d6cc50d15b459feb6010a989fcb7f5b (patch) | |
tree | 8211a9b8b29b749270c6d71f4faf6073e1a382cb | |
parent | 1a4dd47d5f691f77f5a11dbb5cdd8d58b2336245 (diff) | |
download | serenity-8260135d4d6cc50d15b459feb6010a989fcb7f5b.zip |
LibCore+Everywhere: Return ErrorOr from ConfigFile factory methods
I've attempted to handle the errors gracefully where it was clear how to
do so, and simple, but a lot of this was just adding
`release_value_but_fixme_should_propagate_errors()` in places.
31 files changed, 77 insertions, 51 deletions
diff --git a/Meta/Lagom/Tools/ConfigureComponents/main.cpp b/Meta/Lagom/Tools/ConfigureComponents/main.cpp index 058493666e..c09dedbe61 100644 --- a/Meta/Lagom/Tools/ConfigureComponents/main.cpp +++ b/Meta/Lagom/Tools/ConfigureComponents/main.cpp @@ -241,7 +241,7 @@ int main() } // Step 2: Open and parse the 'components.ini' file. - auto components_file = Core::ConfigFile::open("components.ini"); + auto components_file = Core::ConfigFile::open("components.ini").release_value_but_fixme_should_propagate_errors(); if (components_file->groups().is_empty()) { warnln("\e[31mError:\e[0m The 'components.ini' file is either not a valid ini file or contains no entries."); return 1; diff --git a/Tests/LibTLS/TestTLSHandshake.cpp b/Tests/LibTLS/TestTLSHandshake.cpp index 2784e3a151..c9bd3845a8 100644 --- a/Tests/LibTLS/TestTLSHandshake.cpp +++ b/Tests/LibTLS/TestTLSHandshake.cpp @@ -45,7 +45,7 @@ Vector<Certificate> load_certificates() return certificates; } - auto config = Core::ConfigFile::open(ca_certs_filepath); + auto config = Core::ConfigFile::open(ca_certs_filepath).release_value_but_fixme_should_propagate_errors(); auto now = Core::DateTime::now(); auto last_year = Core::DateTime::create(now.year() - 1); auto next_year = Core::DateTime::create(now.year() + 1); diff --git a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp index 38bae7e44d..0a7e222cc6 100644 --- a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp +++ b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp @@ -105,7 +105,7 @@ void BackgroundSettingsWidget::create_frame() void BackgroundSettingsWidget::load_current_settings() { - auto ws_config = Core::ConfigFile::open("/etc/WindowServer.ini"); + auto ws_config = Core::ConfigFile::open("/etc/WindowServer.ini").release_value_but_fixme_should_propagate_errors(); auto selected_wallpaper = Config::read_string("WindowManager", "Background", "Wallpaper", ""); if (!selected_wallpaper.is_empty()) { diff --git a/Userland/Applications/KeyboardSettings/KeyboardSettingsWidget.cpp b/Userland/Applications/KeyboardSettings/KeyboardSettingsWidget.cpp index eba887b3cc..2a697b3e15 100644 --- a/Userland/Applications/KeyboardSettings/KeyboardSettingsWidget.cpp +++ b/Userland/Applications/KeyboardSettings/KeyboardSettingsWidget.cpp @@ -144,7 +144,7 @@ KeyboardSettingsWidget::KeyboardSettingsWidget() m_current_applied_keymap = keymap_object.get("keymap").to_string(); dbgln("KeyboardSettings thinks the current keymap is: {}", m_current_applied_keymap); - auto mapper_config(Core::ConfigFile::open("/etc/Keyboard.ini")); + auto mapper_config(Core::ConfigFile::open("/etc/Keyboard.ini").release_value_but_fixme_should_propagate_errors()); auto keymaps = mapper_config->read_entry("Mapping", "Keymaps", ""); auto keymaps_vector = keymaps.split(','); diff --git a/Userland/Applications/ThemeEditor/PreviewWidget.cpp b/Userland/Applications/ThemeEditor/PreviewWidget.cpp index 49ae0f3114..0c23c73ae1 100644 --- a/Userland/Applications/ThemeEditor/PreviewWidget.cpp +++ b/Userland/Applications/ThemeEditor/PreviewWidget.cpp @@ -141,7 +141,7 @@ void PreviewWidget::set_preview_palette(const Gfx::Palette& palette) void PreviewWidget::set_theme_from_file(Core::File& file) { - auto config_file = Core::ConfigFile::open(file.filename(), file.leak_fd()); + auto config_file = Core::ConfigFile::open(file.filename(), file.leak_fd()).release_value_but_fixme_should_propagate_errors(); auto theme = Gfx::load_system_theme(config_file); VERIFY(theme.is_valid()); diff --git a/Userland/Applications/ThemeEditor/main.cpp b/Userland/Applications/ThemeEditor/main.cpp index 6c5e9de3ab..77bc9fb4ef 100644 --- a/Userland/Applications/ThemeEditor/main.cpp +++ b/Userland/Applications/ThemeEditor/main.cpp @@ -357,7 +357,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) update_window_title(); auto file = response.value(); - auto theme = Core::ConfigFile::open(file->filename(), file->leak_fd()); + auto theme = Core::ConfigFile::open(file->filename(), file->leak_fd()).release_value_but_fixme_should_propagate_errors(); for (auto role : color_roles) { theme->write_entry("Colors", to_string(role), preview_widget.preview_palette().color(role).to_string()); } diff --git a/Userland/DevTools/HackStudio/ProjectTemplate.cpp b/Userland/DevTools/HackStudio/ProjectTemplate.cpp index 34a2523624..2f823c9143 100644 --- a/Userland/DevTools/HackStudio/ProjectTemplate.cpp +++ b/Userland/DevTools/HackStudio/ProjectTemplate.cpp @@ -30,7 +30,10 @@ ProjectTemplate::ProjectTemplate(const String& id, const String& name, const Str RefPtr<ProjectTemplate> ProjectTemplate::load_from_manifest(const String& manifest_path) { - auto config = Core::ConfigFile::open(manifest_path); + auto maybe_config = Core::ConfigFile::open(manifest_path); + if (maybe_config.is_error()) + return {}; + auto config = maybe_config.release_value(); if (!config->has_group("HackStudioTemplate") || !config->has_key("HackStudioTemplate", "Name") diff --git a/Userland/Libraries/LibCore/ConfigFile.cpp b/Userland/Libraries/LibCore/ConfigFile.cpp index 4aad3df7e7..3ca378cc02 100644 --- a/Userland/Libraries/LibCore/ConfigFile.cpp +++ b/Userland/Libraries/LibCore/ConfigFile.cpp @@ -14,35 +14,35 @@ namespace Core { -NonnullRefPtr<ConfigFile> ConfigFile::open_for_lib(String const& lib_name, AllowWriting allow_altering) +ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open_for_lib(String const& lib_name, AllowWriting allow_altering) { String directory = StandardPaths::config_directory(); auto path = String::formatted("{}/lib/{}.ini", directory, lib_name); - return adopt_ref(*new ConfigFile(path, allow_altering)); + return adopt_nonnull_ref_or_enomem(new (nothrow) ConfigFile(path, allow_altering)); } -NonnullRefPtr<ConfigFile> ConfigFile::open_for_app(String const& app_name, AllowWriting allow_altering) +ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open_for_app(String const& app_name, AllowWriting allow_altering) { String directory = StandardPaths::config_directory(); auto path = String::formatted("{}/{}.ini", directory, app_name); - return adopt_ref(*new ConfigFile(path, allow_altering)); + return adopt_nonnull_ref_or_enomem(new (nothrow) ConfigFile(path, allow_altering)); } -NonnullRefPtr<ConfigFile> ConfigFile::open_for_system(String const& app_name, AllowWriting allow_altering) +ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open_for_system(String const& app_name, AllowWriting allow_altering) { auto path = String::formatted("/etc/{}.ini", app_name); - return adopt_ref(*new ConfigFile(path, allow_altering)); + return adopt_nonnull_ref_or_enomem(new (nothrow) ConfigFile(path, allow_altering)); } -NonnullRefPtr<ConfigFile> ConfigFile::open(String const& filename, AllowWriting allow_altering) +ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(String const& filename, AllowWriting allow_altering) { - return adopt_ref(*new ConfigFile(filename, allow_altering)); + return adopt_nonnull_ref_or_enomem(new (nothrow) ConfigFile(filename, allow_altering)); } -NonnullRefPtr<ConfigFile> ConfigFile::open(String const& filename, int fd) +ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(String const& filename, int fd) { - return adopt_ref(*new ConfigFile(filename, fd)); + return adopt_nonnull_ref_or_enomem(new (nothrow) ConfigFile(filename, fd)); } ConfigFile::ConfigFile(String const& filename, AllowWriting allow_altering) diff --git a/Userland/Libraries/LibCore/ConfigFile.h b/Userland/Libraries/LibCore/ConfigFile.h index d2262cbb56..ff3de3bb7b 100644 --- a/Userland/Libraries/LibCore/ConfigFile.h +++ b/Userland/Libraries/LibCore/ConfigFile.h @@ -24,11 +24,11 @@ public: No, }; - static NonnullRefPtr<ConfigFile> open_for_lib(String const& lib_name, AllowWriting = AllowWriting::No); - static NonnullRefPtr<ConfigFile> open_for_app(String const& app_name, AllowWriting = AllowWriting::No); - static NonnullRefPtr<ConfigFile> open_for_system(String const& app_name, AllowWriting = AllowWriting::No); - static NonnullRefPtr<ConfigFile> open(String const& filename, AllowWriting = AllowWriting::No); - static NonnullRefPtr<ConfigFile> open(String const& filename, int fd); + static ErrorOr<NonnullRefPtr<ConfigFile>> open_for_lib(String const& lib_name, AllowWriting = AllowWriting::No); + static ErrorOr<NonnullRefPtr<ConfigFile>> open_for_app(String const& app_name, AllowWriting = AllowWriting::No); + static ErrorOr<NonnullRefPtr<ConfigFile>> open_for_system(String const& app_name, AllowWriting = AllowWriting::No); + static ErrorOr<NonnullRefPtr<ConfigFile>> open(String const& filename, AllowWriting = AllowWriting::No); + static ErrorOr<NonnullRefPtr<ConfigFile>> open(String const& filename, int fd); ~ConfigFile(); bool has_group(String const&) const; diff --git a/Userland/Libraries/LibCore/Version.cpp b/Userland/Libraries/LibCore/Version.cpp index 9857789871..8a162e9d65 100644 --- a/Userland/Libraries/LibCore/Version.cpp +++ b/Userland/Libraries/LibCore/Version.cpp @@ -11,7 +11,7 @@ namespace Core::Version { String read_long_version_string() { - auto version_config = Core::ConfigFile::open("/res/version.ini"); + auto version_config = Core::ConfigFile::open("/res/version.ini").release_value_but_fixme_should_propagate_errors(); auto major_version = version_config->read_entry("Version", "Major", "0"); auto minor_version = version_config->read_entry("Version", "Minor", "0"); diff --git a/Userland/Libraries/LibDesktop/AppFile.cpp b/Userland/Libraries/LibDesktop/AppFile.cpp index bbaf23f3c1..d73a468ea1 100644 --- a/Userland/Libraries/LibDesktop/AppFile.cpp +++ b/Userland/Libraries/LibDesktop/AppFile.cpp @@ -43,7 +43,7 @@ void AppFile::for_each(Function<void(NonnullRefPtr<AppFile>)> callback, StringVi } AppFile::AppFile(StringView path) - : m_config(Core::ConfigFile::open(path)) + : m_config(Core::ConfigFile::open(path).release_value_but_fixme_should_propagate_errors()) , m_valid(validate()) { } diff --git a/Userland/Libraries/LibGUI/FileIconProvider.cpp b/Userland/Libraries/LibGUI/FileIconProvider.cpp index dbed2680ca..1b14a87a48 100644 --- a/Userland/Libraries/LibGUI/FileIconProvider.cpp +++ b/Userland/Libraries/LibGUI/FileIconProvider.cpp @@ -64,7 +64,7 @@ static void initialize_if_needed() if (s_initialized) return; - auto config = Core::ConfigFile::open("/etc/FileIconProvider.ini"); + auto config = Core::ConfigFile::open("/etc/FileIconProvider.ini").release_value_but_fixme_should_propagate_errors(); s_symlink_emblem = Gfx::Bitmap::try_load_from_file("/res/icons/symlink-emblem.png").release_value_but_fixme_should_propagate_errors(); s_symlink_emblem_small = Gfx::Bitmap::try_load_from_file("/res/icons/symlink-emblem-small.png").release_value_but_fixme_should_propagate_errors(); diff --git a/Userland/Libraries/LibGfx/SystemTheme.cpp b/Userland/Libraries/LibGfx/SystemTheme.cpp index d6e7d16846..ed52299c08 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.cpp +++ b/Userland/Libraries/LibGfx/SystemTheme.cpp @@ -147,7 +147,7 @@ Core::AnonymousBuffer load_system_theme(Core::ConfigFile const& file) Core::AnonymousBuffer load_system_theme(String const& path) { - return load_system_theme(Core::ConfigFile::open(path)); + return load_system_theme(Core::ConfigFile::open(path).release_value_but_fixme_should_propagate_errors()); } } diff --git a/Userland/Libraries/LibLine/Editor.cpp b/Userland/Libraries/LibLine/Editor.cpp index 02ae0f2496..3863131c10 100644 --- a/Userland/Libraries/LibLine/Editor.cpp +++ b/Userland/Libraries/LibLine/Editor.cpp @@ -40,7 +40,7 @@ namespace Line { Configuration Configuration::from_config(StringView libname) { Configuration configuration; - auto config_file = Core::ConfigFile::open_for_lib(libname); + auto config_file = Core::ConfigFile::open_for_lib(libname).release_value_but_fixme_should_propagate_errors(); // Read behavior options. auto refresh = config_file->read_entry("behavior", "refresh", "lazy"); diff --git a/Userland/Libraries/LibTLS/TLSv12.cpp b/Userland/Libraries/LibTLS/TLSv12.cpp index 0fb57f43ae..bd9a2a4280 100644 --- a/Userland/Libraries/LibTLS/TLSv12.cpp +++ b/Userland/Libraries/LibTLS/TLSv12.cpp @@ -345,7 +345,7 @@ Singleton<DefaultRootCACertificates> DefaultRootCACertificates::s_the; DefaultRootCACertificates::DefaultRootCACertificates() { // FIXME: This might not be the best format, find a better way to represent CA certificates. - auto config = Core::ConfigFile::open_for_system("ca_certs"); + auto config = Core::ConfigFile::open_for_system("ca_certs").release_value_but_fixme_should_propagate_errors(); auto now = Core::DateTime::now(); auto last_year = Core::DateTime::create(now.year() - 1); auto next_year = Core::DateTime::create(now.year() + 1); diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index c47cdc004d..9c51cf93e8 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -1196,7 +1196,13 @@ void TerminalWidget::set_color_scheme(StringView name) "White" }; - auto color_config = Core::ConfigFile::open(String::formatted("/res/terminal-colors/{}.ini", name)); + auto path = String::formatted("/res/terminal-colors/{}.ini", name); + auto color_config_or_error = Core::ConfigFile::open(path); + if (color_config_or_error.is_error()) { + dbgln("Unable to read color scheme file '{}': {}", path, color_config_or_error.error()); + return; + } + auto color_config = color_config_or_error.release_value(); m_show_bold_text_as_bright = color_config->read_bool_entry("Options", "ShowBoldTextAsBright", true); diff --git a/Userland/Services/AudioServer/main.cpp b/Userland/Services/AudioServer/main.cpp index dd8da23147..b659484659 100644 --- a/Userland/Services/AudioServer/main.cpp +++ b/Userland/Services/AudioServer/main.cpp @@ -15,7 +15,7 @@ ErrorOr<int> serenity_main(Main::Arguments) { TRY(Core::System::pledge("stdio recvfd thread accept cpath rpath wpath unix")); - auto config = Core::ConfigFile::open_for_app("Audio", Core::ConfigFile::AllowWriting::Yes); + auto config = TRY(Core::ConfigFile::open_for_app("Audio", Core::ConfigFile::AllowWriting::Yes)); TRY(Core::System::unveil(config->filename(), "rwc")); TRY(Core::System::unveil("/dev/audio", "wc")); TRY(Core::System::unveil(nullptr, nullptr)); diff --git a/Userland/Services/ConfigServer/ClientConnection.cpp b/Userland/Services/ConfigServer/ClientConnection.cpp index 75dab718ae..35ddf332e8 100644 --- a/Userland/Services/ConfigServer/ClientConnection.cpp +++ b/Userland/Services/ConfigServer/ClientConnection.cpp @@ -37,14 +37,14 @@ static Core::ConfigFile& ensure_domain_config(String const& domain) if (it != s_cache.end()) return *it->value->config; - auto config = Core::ConfigFile::open_for_app(domain, Core::ConfigFile::AllowWriting::Yes); + auto config = Core::ConfigFile::open_for_app(domain, Core::ConfigFile::AllowWriting::Yes).release_value_but_fixme_should_propagate_errors(); // FIXME: Use a single FileWatcher with multiple watches inside. auto watcher_or_error = Core::FileWatcher::create(InodeWatcherFlags::Nonblock); VERIFY(!watcher_or_error.is_error()); auto result = watcher_or_error.value()->add_watch(config->filename(), Core::FileWatcherEvent::Type::ContentModified); VERIFY(!result.is_error()); watcher_or_error.value()->on_change = [config, domain](auto&) { - auto new_config = Core::ConfigFile::open(config->filename(), Core::ConfigFile::AllowWriting::Yes); + auto new_config = Core::ConfigFile::open(config->filename(), Core::ConfigFile::AllowWriting::Yes).release_value_but_fixme_should_propagate_errors(); for (auto& group : config->groups()) { for (auto& key : config->keys(group)) { if (!new_config->has_key(group, key)) { diff --git a/Userland/Services/KeyboardPreferenceLoader/main.cpp b/Userland/Services/KeyboardPreferenceLoader/main.cpp index 2c035f23a6..cfd231d13c 100644 --- a/Userland/Services/KeyboardPreferenceLoader/main.cpp +++ b/Userland/Services/KeyboardPreferenceLoader/main.cpp @@ -17,13 +17,13 @@ ErrorOr<int> serenity_main(Main::Arguments) { TRY(Core::System::pledge("stdio proc exec rpath")); - auto keyboard_settings_config = Core::ConfigFile::open_for_app("KeyboardSettings"); + auto keyboard_settings_config = TRY(Core::ConfigFile::open_for_app("KeyboardSettings")); TRY(Core::System::unveil("/bin/keymap", "x")); TRY(Core::System::unveil("/etc/Keyboard.ini", "r")); TRY(Core::System::unveil("/dev/keyboard0", "r")); TRY(Core::System::unveil(nullptr, nullptr)); - auto mapper_config(Core::ConfigFile::open("/etc/Keyboard.ini")); + auto mapper_config = TRY(Core::ConfigFile::open("/etc/Keyboard.ini")); auto keymaps = mapper_config->read_entry("Mapping", "Keymaps", ""); auto keymaps_vector = keymaps.split(','); diff --git a/Userland/Services/LaunchServer/main.cpp b/Userland/Services/LaunchServer/main.cpp index befe4af84b..a9c08060d6 100644 --- a/Userland/Services/LaunchServer/main.cpp +++ b/Userland/Services/LaunchServer/main.cpp @@ -19,7 +19,7 @@ ErrorOr<int> serenity_main(Main::Arguments) auto launcher = LaunchServer::Launcher(); launcher.load_handlers(); - launcher.load_config(Core::ConfigFile::open_for_app("LaunchServer")); + launcher.load_config(TRY(Core::ConfigFile::open_for_app("LaunchServer"))); TRY(Core::System::pledge("stdio accept rpath proc exec")); diff --git a/Userland/Services/LookupServer/LookupServer.cpp b/Userland/Services/LookupServer/LookupServer.cpp index 676988f8cc..0edaeb6d54 100644 --- a/Userland/Services/LookupServer/LookupServer.cpp +++ b/Userland/Services/LookupServer/LookupServer.cpp @@ -37,7 +37,7 @@ LookupServer::LookupServer() VERIFY(s_the == nullptr); s_the = this; - auto config = Core::ConfigFile::open_for_system("LookupServer"); + auto config = Core::ConfigFile::open_for_system("LookupServer").release_value_but_fixme_should_propagate_errors(); dbgln("Using network config file at {}", config->filename()); m_nameservers = config->read_entry("DNS", "Nameservers", "1.1.1.1,1.0.0.1").split(','); diff --git a/Userland/Services/SystemServer/main.cpp b/Userland/Services/SystemServer/main.cpp index 85664277d3..d6b081e57a 100644 --- a/Userland/Services/SystemServer/main.cpp +++ b/Userland/Services/SystemServer/main.cpp @@ -489,8 +489,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) // This takes care of setting up sockets. NonnullRefPtrVector<Service> services; auto config = (user) - ? Core::ConfigFile::open_for_app("SystemServer") - : Core::ConfigFile::open_for_system("SystemServer"); + ? TRY(Core::ConfigFile::open_for_app("SystemServer")) + : TRY(Core::ConfigFile::open_for_system("SystemServer")); for (auto name : config->groups()) { auto service = Service::construct(*config, name); if (service->is_enabled()) diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp index d581256f57..fe7adb4ac9 100644 --- a/Userland/Services/Taskbar/main.cpp +++ b/Userland/Services/Taskbar/main.cpp @@ -121,7 +121,7 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu() system_menu->add_separator(); // First we construct all the necessary app category submenus. - auto category_icons = Core::ConfigFile::open("/res/icons/SystemMenu.ini"); + auto category_icons = TRY(Core::ConfigFile::open("/res/icons/SystemMenu.ini")); HashMap<String, NonnullRefPtr<GUI::Menu>> app_category_menus; Function<void(String const&)> create_category_menu; diff --git a/Userland/Services/WindowServer/AppletManager.cpp b/Userland/Services/WindowServer/AppletManager.cpp index f3cce8d789..607ed20816 100644 --- a/Userland/Services/WindowServer/AppletManager.cpp +++ b/Userland/Services/WindowServer/AppletManager.cpp @@ -20,7 +20,7 @@ AppletManager::AppletManager() { s_the = this; - auto wm_config = Core::ConfigFile::open("/etc/WindowServer.ini"); + auto wm_config = Core::ConfigFile::open("/etc/WindowServer.ini").release_value_but_fixme_should_propagate_errors(); auto order = wm_config->read_entry("Applet", "Order"); order_vector = order.split(','); } diff --git a/Userland/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp index 3e5f6fb7d7..0042bf7cec 100644 --- a/Userland/Services/WindowServer/ClientConnection.cpp +++ b/Userland/Services/WindowServer/ClientConnection.cpp @@ -786,7 +786,7 @@ Messages::WindowServer::SetSystemThemeResponse ClientConnection::set_system_them Messages::WindowServer::GetSystemThemeResponse ClientConnection::get_system_theme() { - auto wm_config = Core::ConfigFile::open("/etc/WindowServer.ini"); + auto wm_config = Core::ConfigFile::open("/etc/WindowServer.ini").release_value_but_fixme_should_propagate_errors(); auto name = wm_config->read_entry("Theme", "Name"); return name; } @@ -798,7 +798,7 @@ void ClientConnection::apply_cursor_theme(String const& name) Messages::WindowServer::GetCursorThemeResponse ClientConnection::get_cursor_theme() { - auto config = Core::ConfigFile::open("/etc/WindowServer.ini"); + auto config = Core::ConfigFile::open("/etc/WindowServer.ini").release_value_but_fixme_should_propagate_errors(); auto name = config->read_entry("Mouse", "CursorTheme"); return name; } @@ -822,7 +822,12 @@ Messages::WindowServer::SetSystemFontsResponse ClientConnection::set_system_font WindowManager::the().invalidate_after_theme_or_font_change(); - auto wm_config = Core::ConfigFile::open("/etc/WindowServer.ini", Core::ConfigFile::AllowWriting::Yes); + auto wm_config_or_error = Core::ConfigFile::open("/etc/WindowServer.ini", Core::ConfigFile::AllowWriting::Yes); + if (wm_config_or_error.is_error()) { + dbgln("Unable to open WindowServer.ini to set system fonts: {}", wm_config_or_error.error()); + return false; + } + auto wm_config = wm_config_or_error.release_value(); wm_config->write_entry("Fonts", "Default", default_font_query); wm_config->write_entry("Fonts", "FixedWidth", fixed_width_font_query); return true; diff --git a/Userland/Services/WindowServer/KeymapSwitcher.cpp b/Userland/Services/WindowServer/KeymapSwitcher.cpp index 3de9a8c373..ac47e2473b 100644 --- a/Userland/Services/WindowServer/KeymapSwitcher.cpp +++ b/Userland/Services/WindowServer/KeymapSwitcher.cpp @@ -34,7 +34,7 @@ void KeymapSwitcher::refresh() { m_keymaps.clear(); - auto mapper_config(Core::ConfigFile::open(m_keyboard_config)); + auto mapper_config(Core::ConfigFile::open(m_keyboard_config).release_value_but_fixme_should_propagate_errors()); auto keymaps = mapper_config->read_entry("Mapping", "Keymaps", ""); auto keymaps_vector = keymaps.split(','); diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index f0f57e4147..feaafc8418 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -74,7 +74,7 @@ WindowManager::~WindowManager() void WindowManager::reload_config() { - m_config = Core::ConfigFile::open("/etc/WindowServer.ini", Core::ConfigFile::AllowWriting::Yes); + m_config = Core::ConfigFile::open("/etc/WindowServer.ini", Core::ConfigFile::AllowWriting::Yes).release_value_but_fixme_should_propagate_errors(); unsigned workspace_rows = (unsigned)m_config->read_num_entry("Workspace", "Rows", default_window_stack_rows); unsigned workspace_columns = (unsigned)m_config->read_num_entry("Workspace", "Columns", default_window_stack_columns); @@ -2193,9 +2193,15 @@ WindowStack& WindowManager::get_rendering_window_stacks(WindowStack*& transition return Compositor::the().get_rendering_window_stacks(transitioning_window_stack); } -void WindowManager::apply_cursor_theme(const String& theme_name) +void WindowManager::apply_cursor_theme(String const& theme_name) { - auto cursor_theme_config = Core::ConfigFile::open(String::formatted("/res/cursor-themes/{}/{}", theme_name, "Config.ini")); + auto theme_path = String::formatted("/res/cursor-themes/{}/{}", theme_name, "Config.ini"); + auto cursor_theme_config_or_error = Core::ConfigFile::open(theme_path); + if (cursor_theme_config_or_error.is_error()) { + dbgln("Unable to open cursor theme '{}': {}", theme_path, cursor_theme_config_or_error.error()); + return; + } + auto cursor_theme_config = cursor_theme_config_or_error.release_value(); auto* current_cursor = Compositor::the().current_cursor(); auto reload_cursor = [&](RefPtr<Cursor>& cursor, const String& name) { diff --git a/Userland/Services/WindowServer/main.cpp b/Userland/Services/WindowServer/main.cpp index bb26ef29ad..2c56729bd7 100644 --- a/Userland/Services/WindowServer/main.cpp +++ b/Userland/Services/WindowServer/main.cpp @@ -36,7 +36,7 @@ ErrorOr<int> serenity_main(Main::Arguments) TRY(Core::System::sigaction(SIGCHLD, &act, nullptr)); TRY(Core::System::pledge("stdio video thread sendfd recvfd accept rpath wpath cpath unix proc exec")); - auto wm_config = Core::ConfigFile::open("/etc/WindowServer.ini"); + auto wm_config = TRY(Core::ConfigFile::open("/etc/WindowServer.ini")); auto theme_name = wm_config->read_entry("Theme", "Name", "Default"); auto theme = Gfx::load_system_theme(String::formatted("/res/themes/{}.ini", theme_name)); diff --git a/Userland/Utilities/ini.cpp b/Userland/Utilities/ini.cpp index 191b707e14..e1b7ae904e 100644 --- a/Userland/Utilities/ini.cpp +++ b/Userland/Utilities/ini.cpp @@ -31,7 +31,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) return 1; } - auto config = Core::ConfigFile::open(path, value_to_write ? Core::ConfigFile::AllowWriting::Yes : Core::ConfigFile::AllowWriting::No); + auto config = TRY(Core::ConfigFile::open(path, value_to_write ? Core::ConfigFile::AllowWriting::Yes : Core::ConfigFile::AllowWriting::No)); if (value_to_write) { config->write_entry(group, key, value_to_write); diff --git a/Userland/Utilities/keymap.cpp b/Userland/Utilities/keymap.cpp index 0818798109..8db477cbbf 100644 --- a/Userland/Utilities/keymap.cpp +++ b/Userland/Utilities/keymap.cpp @@ -53,7 +53,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) return 0; } - auto mapper_config(Core::ConfigFile::open("/etc/Keyboard.ini", Core::ConfigFile::AllowWriting::Yes)); + auto mapper_config = TRY(Core::ConfigFile::open("/etc/Keyboard.ini", Core::ConfigFile::AllowWriting::Yes)); int rc = 0; diff --git a/Userland/Utilities/run-tests.cpp b/Userland/Utilities/run-tests.cpp index 5941d2f26f..23f33a48b1 100644 --- a/Userland/Utilities/run-tests.cpp +++ b/Userland/Utilities/run-tests.cpp @@ -376,7 +376,13 @@ int main(int argc, char** argv) return 1; } - auto config = config_file.is_empty() ? Core::ConfigFile::open_for_app("Tests") : Core::ConfigFile::open(config_file); + auto config_or_error = config_file.is_empty() ? Core::ConfigFile::open_for_app("Tests") : Core::ConfigFile::open(config_file); + if (config_or_error.is_error()) { + warnln("Failed to open configuration file ({}): {}", config_file.is_empty() ? "User config for Tests" : config_file.characters(), config_or_error.error()); + return 1; + } + auto config = config_or_error.release_value(); + if (config->num_groups() == 0) warnln("Empty configuration file ({}) loaded!", config_file.is_empty() ? "User config for Tests" : config_file.characters()); |