Skip to content

Commit

Permalink
add more error information when parsing virtual configs and treat emp…
Browse files Browse the repository at this point in the history
…ty type differently (#8)

Co-authored-by: Nathan Hughes <[email protected]>
  • Loading branch information
nathanhhughes and nathanhhughes committed Mar 14, 2024
1 parent 2735fd7 commit 51feae3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 8 additions & 6 deletions config_utilities/include/config_utilities/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@ struct ModuleMapBase {
return false;
}
if (map.find(type) == map.end()) {
std::string module_list;
for (const auto& entry : map) {
module_list.append(entry.first + "', '");
if (!type.empty()) {
std::string module_list;
for (const auto& entry : map) {
module_list.append(entry.first + "', '");
}
module_list = module_list.substr(0, module_list.size() - 4);
Logger::logError("No module of type '" + type + "' registered to the factory for " + type_info +
". Registered are: '" + module_list + "'.");
}
module_list = module_list.substr(0, module_list.size() - 4);
Logger::logError("No module of type '" + type + "' registered to the factory for " + type_info +
". Registered are: '" + module_list + "'.");
return false;
}
return true;
Expand Down
6 changes: 6 additions & 0 deletions config_utilities/include/config_utilities/virtual_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class VirtualConfig {
*/
void setOptional(bool optional = true) { optional_ = optional; }

bool optional() const { return optional_; }

/**
* @brief Get the string-identifier-type of the config stored in the virtual config.
*/
Expand Down Expand Up @@ -166,6 +168,10 @@ void declare_config(VirtualConfig<BaseT>& config) {
: internal::getType(*data, type);
if (success) {
config.config_ = internal::ConfigFactory<BaseT>::create(type);
} else if (!config.optional_) {
std::stringstream ss;
ss << "Could not get type for '" << internal::typeInfo<BaseT>() << "'";
internal::Logger::logError(ss.str());
}
}

Expand Down

0 comments on commit 51feae3

Please sign in to comment.