mirror of
https://github.com/RGBCube/serenity
synced 2025-08-05 07:57:34 +00:00
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.
This commit is contained in:
parent
1a4dd47d5f
commit
8260135d4d
31 changed files with 77 additions and 51 deletions
|
@ -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));
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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(',');
|
||||
|
|
|
@ -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"));
|
||||
|
||||
|
|
|
@ -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(',');
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(',');
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(',');
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue