mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 02:27:44 +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
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue