Skip to content

Commit 596f0db

Browse files
authored
DPL: print an error when the configuration is not parsed correctly (#14727)
This should probably be a fatal error not sure why the rethrown exception is ignored (and where).
1 parent d56b3e9 commit 596f0db

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

Framework/Core/src/PropertyTreeHelpers.cxx

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
#include "Framework/VariantPropertyTreeHelpers.h"
1515
#include "Framework/RuntimeError.h"
1616
#include "Framework/VariantJSONHelpers.h"
17+
#include "Framework/Signpost.h"
1718

1819
#include <boost/program_options/variables_map.hpp>
1920

2021
#include <vector>
2122
#include <string>
2223

24+
O2_DECLARE_DYNAMIC_LOG(configuration);
25+
2326
namespace o2::framework
2427
{
2528
namespace
@@ -37,6 +40,8 @@ void PropertyTreeHelpers::populateDefaults(std::vector<ConfigParamSpec> const& s
3740
boost::property_tree::ptree& pt,
3841
boost::property_tree::ptree& provenance)
3942
{
43+
O2_SIGNPOST_ID_GENERATE(cid, configuration);
44+
O2_SIGNPOST_START(configuration, cid, "populateDefaults", "Filling with defaults");
4045
for (auto const& spec : schema) {
4146
std::string key = spec.name.substr(0, spec.name.find(','));
4247
try {
@@ -77,9 +82,12 @@ void PropertyTreeHelpers::populateDefaults(std::vector<ConfigParamSpec> const& s
7782
case VariantType::String:
7883
pt.put(key, spec.defaultValue.get<std::string>());
7984
break;
80-
case VariantType::Bool:
81-
pt.put(key, spec.defaultValue.get<bool>());
85+
case VariantType::Bool: {
86+
bool value = spec.defaultValue.get<bool>();
87+
O2_SIGNPOST_EVENT_EMIT(configuration, cid, "populateDefaults", "Setting %{public}s: %{public}s", key.c_str(), value ? "true" : "false");
88+
pt.put(key, value);
8289
break;
90+
}
8391
case VariantType::Dict:
8492
pt.put_child(key, boost::property_tree::ptree{});
8593
break;
@@ -126,20 +134,26 @@ void PropertyTreeHelpers::populateDefaults(std::vector<ConfigParamSpec> const& s
126134
}
127135
provenance.put(key, "default");
128136
} catch (std::runtime_error& re) {
137+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populateDefaults", "Aborting because of runtime_error %{public}s", re.what());
129138
throw;
130139
} catch (std::exception& e) {
140+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populateDefaults", "Missing option %{public}s (%{public}s)", key.c_str(), e.what());
131141
throw std::invalid_argument(std::string("missing option: ") + key + " (" + e.what() + ")");
132142
} catch (...) {
143+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populateDefaults", "Aborting because of missing option %{public}s", key.c_str());
133144
throw std::invalid_argument(std::string("missing option: ") + key);
134145
}
135146
}
147+
O2_SIGNPOST_END(configuration, cid, "populateDefaults", "Done");
136148
}
137149

138150
void PropertyTreeHelpers::populate(std::vector<ConfigParamSpec> const& schema,
139151
boost::property_tree::ptree& pt,
140152
boost::program_options::variables_map const& vmap,
141153
boost::property_tree::ptree& provenance)
142154
{
155+
O2_SIGNPOST_ID_GENERATE(cid, configuration);
156+
O2_SIGNPOST_START(configuration, cid, "populate", "Filling parameters from variables_map");
143157
for (auto const& spec : schema) {
144158
// strip short version to get the correct key
145159
std::string key = spec.name.substr(0, spec.name.find(','));
@@ -183,9 +197,11 @@ void PropertyTreeHelpers::populate(std::vector<ConfigParamSpec> const& schema,
183197
pt.put(key, *v);
184198
}
185199
break;
186-
case VariantType::Bool:
187-
pt.put(key, vmap[key].as<bool>());
188-
break;
200+
case VariantType::Bool: {
201+
auto v = vmap[key].as<bool>();
202+
O2_SIGNPOST_EVENT_EMIT(configuration, cid, "populate", "Setting %{public}s: %{public}s", key.c_str(), v ? "true" : "false");
203+
pt.put(key, v);
204+
} break;
189205
case VariantType::ArrayInt: {
190206
auto v = fromString<VariantType::ArrayInt>(vmap[key].as<std::string>());
191207
pt.put_child(key, vectorToBranch<int>(v.get<int*>(), v.size()));
@@ -243,13 +259,17 @@ void PropertyTreeHelpers::populate(std::vector<ConfigParamSpec> const& schema,
243259
}
244260
provenance.put(key, "fairmq");
245261
} catch (std::runtime_error& re) {
262+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populate", "Aborting because of runtime_error %{public}s", re.what());
246263
throw;
247264
} catch (std::exception& e) {
265+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populate", "Missing option %{public}s (%{public}s)", key.c_str(), e.what());
248266
throw std::invalid_argument(std::string("missing option: ") + key + " (" + e.what() + ")");
249267
} catch (...) {
268+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populate", "Aborting because of missing option %{public}s", key.c_str());
250269
throw std::invalid_argument(std::string("missing option: ") + key);
251270
}
252271
}
272+
O2_SIGNPOST_END(configuration, cid, "populate", "Done");
253273
}
254274

255275
template <typename T>
@@ -273,6 +293,8 @@ void PropertyTreeHelpers::populate(std::vector<ConfigParamSpec> const& schema,
273293
boost::property_tree::ptree& provenance,
274294
std::string const& provenanceLabel)
275295
{
296+
O2_SIGNPOST_ID_GENERATE(cid, configuration);
297+
O2_SIGNPOST_START(configuration, cid, "populate", "Filling parameters from ptree");
276298
for (auto const& spec : schema) {
277299
// strip short version to get the correct key
278300
std::string key = spec.name.substr(0, spec.name.find(','));
@@ -318,9 +340,11 @@ void PropertyTreeHelpers::populate(std::vector<ConfigParamSpec> const& schema,
318340
case VariantType::String:
319341
pt.put(key, (*it).get_value<std::string>());
320342
break;
321-
case VariantType::Bool:
343+
case VariantType::Bool: {
344+
auto v = (*it).get_value<bool>();
345+
O2_SIGNPOST_EVENT_EMIT(configuration, cid, "populate", "Setting %{public}s: %{public}s", key.c_str(), v ? "true" : "false");
322346
pt.put(key, (*it).get_value<bool>());
323-
break;
347+
} break;
324348
case VariantType::Dict:
325349
case VariantType::ArrayInt:
326350
case VariantType::ArrayFloat:
@@ -371,13 +395,18 @@ void PropertyTreeHelpers::populate(std::vector<ConfigParamSpec> const& schema,
371395
}
372396
provenance.put(key, provenanceLabel);
373397
} catch (std::runtime_error& re) {
398+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populate", "Aborting during processing of %{public}s because of runtime_error %{public}s",
399+
key.c_str(), re.what());
374400
throw;
375401
} catch (std::exception& e) {
402+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populate", "Missing option %{public}s (%{public}s)", key.c_str(), e.what());
376403
throw std::invalid_argument(std::string("missing option: ") + key + " (" + e.what() + ")");
377404
} catch (...) {
405+
O2_SIGNPOST_END_WITH_ERROR(configuration, cid, "populate", "Aborting because of missing option %{public}s", key.c_str());
378406
throw std::invalid_argument(std::string("missing option: ") + key);
379407
}
380408
}
409+
O2_SIGNPOST_END(configuration, cid, "populate", "Done");
381410
}
382411

383412
namespace

0 commit comments

Comments
 (0)