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