Skip to content

Commit a93820e

Browse files
committed
ini-parser: emit errors for options not part of the XML spec
1 parent ae04607 commit a93820e

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

src/compound-option.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ void wf::config::update_compound_from_section(
6060
value[0] = suffix;
6161
for (size_t i = 0; i < entries.size(); ++i)
6262
{
63-
if (const auto & entry_option =
64-
section->get_option_or(entries[i]->get_prefix() + suffix);
63+
if (const auto & entry_option = section->get_option_or(entries[i]->get_prefix() + suffix);
6564
entry_option && !should_ignore_option(entry_option))
6665
{
66+
entry_option->priv->could_be_compound = true;
6767
if (entries[i]->is_parsable(entry_option->get_value_str()))
6868
{
6969
value[i + 1] = entry_option->get_value_str();
@@ -83,9 +83,6 @@ void wf::config::update_compound_from_section(
8383
value[i + 1] = *default_value;
8484
} else
8585
{
86-
LOGE("The option ",
87-
section->get_name() + "/" + entries[i]->get_prefix() + suffix,
88-
" is neither specified nor has a default value");
8986
value.clear();
9087
break;
9188
}
@@ -94,6 +91,14 @@ void wf::config::update_compound_from_section(
9491
if (!value.empty())
9592
{
9693
stored_value.push_back(std::move(value));
94+
for (size_t i = 0; i < entries.size(); ++i)
95+
{
96+
if (auto entry_option = section->get_option_or(entries[i]->get_prefix() + suffix))
97+
{
98+
// The option was used as part of the compound option, do not issue warning for it!
99+
entry_option->priv->is_part_compound = true;
100+
}
101+
}
97102
}
98103
}
99104

src/file.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ void wf::config::load_configuration_options_from_string(
353353
for (auto opt : section->get_registered_options())
354354
{
355355
opt->priv->option_in_config_file = (reloaded.count(opt) > 0);
356+
357+
opt->priv->is_part_compound = false; // will be re-set when updating compound options
358+
opt->priv->could_be_compound = false; // will be re-set when updating compound options
359+
356360
if (!opt->priv->option_in_config_file && !opt->is_locked())
357361
{
358362
opt->reset_to_default();
@@ -373,6 +377,27 @@ void wf::config::load_configuration_options_from_string(
373377
}
374378
}
375379
}
380+
381+
for (auto section : config.get_all_sections())
382+
{
383+
for (auto opt : section->get_registered_options())
384+
{
385+
if (!opt->priv->xml && !opt->priv->is_part_compound)
386+
{
387+
if (opt->priv->could_be_compound)
388+
{
389+
LOGW("Option ", section->get_name(), "/", opt->get_name(),
390+
" could not be parsed as part of a compound option: missing entries or wrong type!");
391+
} else
392+
{
393+
LOGW("Loaded option ", section->get_name(), "/", opt->get_name(),
394+
", which does not belong to any registered plugin, nor could be parsed as a part of ",
395+
"a compound list option. Make sure all the relevant XML files are installed and "
396+
"that the option name is spelled correctly!");
397+
}
398+
}
399+
}
400+
}
376401
}
377402

378403
std::string wf::config::save_configuration_options_to_string(

src/option-impl.hpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,6 @@
66
#include <libxml/tree.h>
77
#include <stdint.h>
88

9-
struct wf::config::option_base_t::impl
10-
{
11-
std::string name;
12-
wf::safe_list_t<updated_callback_t*> updated_handlers;
13-
14-
// Number of times the option has been locked
15-
int32_t lock_count = 0;
16-
17-
// Associated XML node
18-
xmlNode *xml;
19-
20-
// Is option in config file?
21-
bool option_in_config_file = false;
22-
};
23-
249
namespace wf
2510
{
2611
namespace config
@@ -37,3 +22,23 @@ void update_compound_from_section(compound_option_t& option,
3722
const std::shared_ptr<section_t>& section);
3823
}
3924
}
25+
26+
struct wf::config::option_base_t::impl
27+
{
28+
std::string name;
29+
wf::safe_list_t<updated_callback_t*> updated_handlers;
30+
31+
// Number of times the option has been locked
32+
int32_t lock_count = 0;
33+
34+
// Associated XML node
35+
xmlNode *xml = nullptr;
36+
37+
// Is option in config file?
38+
bool option_in_config_file = false;
39+
40+
// Is option part of a successfully parsed compound option?
41+
bool is_part_compound = false;
42+
// Does this option match a compound option in part at least?
43+
bool could_be_compound = false;
44+
};

test/file_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ TEST_CASE("wf::config::load_configuration_options_from_string")
9494
EXPECT_LINE(log, "Error in file test:5");
9595
EXPECT_LINE(log, "Error in file test:20");
9696
EXPECT_LINE(log, "Error in file test:21");
97+
98+
// reset logging state for subsequent tests
99+
wf::log::initialize_logging(std::cout, wf::log::LOG_LEVEL_DEBUG,
100+
wf::log::LOG_COLOR_MODE_OFF);
97101
}
98102

99103
TEST_CASE("wf::config::load_configuration_options_from_string - "

0 commit comments

Comments
 (0)