mirror of
https://github.com/PixlOne/logiops.git
synced 2025-09-14 05:46:50 +08:00
Do not throw error if config file does not exist
This commit is contained in:
parent
c5a9c1d0a4
commit
44e319d770
@ -19,6 +19,7 @@
|
||||
#include <Configuration.h>
|
||||
#include <util/log.h>
|
||||
#include <utility>
|
||||
#include <filesystem>
|
||||
#include <ipc_defs.h>
|
||||
|
||||
using namespace logid;
|
||||
@ -27,19 +28,23 @@ using namespace logid::config;
|
||||
|
||||
Configuration::Configuration(std::string config_file) :
|
||||
_config_file(std::move(config_file)) {
|
||||
try {
|
||||
_config.readFile(_config_file);
|
||||
} catch (const FileIOException& e) {
|
||||
logPrintf(ERROR, "I/O Error while reading %s: %s", _config_file.c_str(),
|
||||
if (std::filesystem::exists(_config_file)) {
|
||||
try {
|
||||
_config.readFile(_config_file);
|
||||
} catch (const FileIOException& e) {
|
||||
logPrintf(ERROR, "I/O Error while reading %s: %s", _config_file.c_str(),
|
||||
e.what());
|
||||
throw;
|
||||
} catch (const ParseException& e) {
|
||||
logPrintf(ERROR, "Parse error in %s, line %d: %s", e.getFile(),
|
||||
throw;
|
||||
} catch (const ParseException& e) {
|
||||
logPrintf(ERROR, "Parse error in %s, line %d: %s", e.getFile(),
|
||||
e.getLine(), e.getError());
|
||||
throw;
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
||||
Config::operator=(get<Config>(_config.getRoot()));
|
||||
Config::operator=(get<Config>(_config.getRoot()));
|
||||
} else {
|
||||
logPrintf(INFO, "Config file does not exist, using empty config.");
|
||||
}
|
||||
|
||||
if (!devices.has_value())
|
||||
devices.emplace();
|
||||
@ -68,4 +73,4 @@ Configuration::IPC::IPC(Configuration* config) :
|
||||
ipcgull::interface(SERVICE_ROOT_NAME ".Config", {
|
||||
{"Save", {config, &Configuration::save}}
|
||||
}, {}, {}) {
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user