mirror of
https://github.com/PixlOne/logiops.git
synced 2025-09-14 13:56:50 +08:00
Fix entire config being invalidated by bad value
This commit is contained in:
parent
fed7e0cacc
commit
455f2cd6c4
@ -12,6 +12,7 @@ find_package(PkgConfig REQUIRED)
|
|||||||
add_executable(logid
|
add_executable(logid
|
||||||
logid.cpp
|
logid.cpp
|
||||||
util/log.cpp
|
util/log.cpp
|
||||||
|
config/util.cpp
|
||||||
InputDevice.cpp
|
InputDevice.cpp
|
||||||
DeviceManager.cpp
|
DeviceManager.cpp
|
||||||
Device.cpp
|
Device.cpp
|
||||||
|
@ -28,11 +28,11 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
/// TODO: A single element failing should not cause the container to be invalid.
|
|
||||||
|
|
||||||
// Containers are chosen specifically so that no iterator is invalidated.
|
// Containers are chosen specifically so that no iterator is invalidated.
|
||||||
|
|
||||||
namespace logid::config {
|
namespace logid::config {
|
||||||
|
void logError(const libconfig::Setting& setting, std::exception& e);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct config_io {
|
struct config_io {
|
||||||
@ -406,10 +406,17 @@ namespace logid::config {
|
|||||||
struct config_io<std::optional<T>> {
|
struct config_io<std::optional<T>> {
|
||||||
static inline std::optional<T> get(const libconfig::Setting& parent,
|
static inline std::optional<T> get(const libconfig::Setting& parent,
|
||||||
const std::string& name) {
|
const std::string& name) {
|
||||||
if (parent.exists(name))
|
if (parent.exists(name)) {
|
||||||
return config_io<T>::get(parent.lookup(name));
|
auto& setting = parent.lookup(name);
|
||||||
else
|
try {
|
||||||
|
return config_io<T>::get(setting);
|
||||||
|
} catch (libconfig::SettingException& e) {
|
||||||
|
logError(setting, e);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void set(libconfig::Setting& parent,
|
static inline void set(libconfig::Setting& parent,
|
||||||
|
26
src/logid/config/util.cpp
Normal file
26
src/logid/config/util.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2023 PixlOne
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config/types.h>
|
||||||
|
#include <util/log.h>
|
||||||
|
|
||||||
|
using namespace logid;
|
||||||
|
|
||||||
|
void config::logError(const libconfig::Setting& setting, std::exception& e) {
|
||||||
|
logPrintf(WARN, "Error at line %d: %s", setting.getSourceLine(), e.what());
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user