diff --git a/kratos/includes/registry_item.h b/kratos/includes/registry_item.h index 44907605ce12..77e366db78b7 100644 --- a/kratos/includes/registry_item.h +++ b/kratos/includes/registry_item.h @@ -340,6 +340,18 @@ class KRATOS_API(KRATOS_CORE) RegistryItem return buffer.str(); } + /** + * @brief Returns the sub items name list available in the registry item (for error messaged). + * @return std::vector The sub items name list. + */ + std::vector GetSubItemAvailableList() const; + + /** + * @brief This method throws an error message for a not found item. + * @param rItemName The name of the item. + */ + void NotFoundError(const std::string& rItemName) const; + ///@} ///@name Private classes ///@{ diff --git a/kratos/sources/registry_item.cpp b/kratos/sources/registry_item.cpp index ad82fbc3d4e3..d7489acaabdf 100644 --- a/kratos/sources/registry_item.cpp +++ b/kratos/sources/registry_item.cpp @@ -91,6 +91,29 @@ namespace Kratos } } + std::vector RegistryItem::GetSubItemAvailableList() const + { + std::vector available_list; + auto it_item_begin = this->cbegin(); + auto it_item_end = this->cend(); + available_list.reserve(std::distance(it_item_begin, it_item_end)); + for (auto it_item = it_item_begin; it_item != it_item_end; ++it_item) { + available_list.push_back((it_item->second)->Name()); + } + return available_list; + } + + void RegistryItem::NotFoundError(const std::string& rItemName) const + { + const std::vector available_list = GetSubItemAvailableList(); + std::stringstream available_list_str; + available_list_str << "The RegistryItem " << this->Name() << " does not have an item with name " << rItemName << ". The available objects are: \n"; + for (std::string const& item : available_list) { + available_list_str << "\t\t" << item << "\n"; + } + KRATOS_ERROR << available_list_str.str() << std::endl; + } + std::string RegistryItem::GetValueString() const { return (this->*(this->mGetValueStringMethod))(); @@ -163,7 +186,9 @@ namespace Kratos { SubRegistryItemType& r_map = GetSubRegistryItemMap(); auto iterator = r_map.find(rItemName); - KRATOS_ERROR_IF(iterator == r_map.end()) << "The RegistryItem " << this->Name() << " does not have an item with name " << rItemName << std::endl; + if (iterator == r_map.end()) { + NotFoundError(rItemName); + } return *(iterator->second); } @@ -171,7 +196,9 @@ namespace Kratos { SubRegistryItemType& r_map = GetSubRegistryItemMap(); auto iterator = r_map.find(rItemName); - KRATOS_ERROR_IF(iterator == r_map.end()) << "The RegistryItem " << this->Name() << " does not have an item with name " << rItemName << std::endl; + if (iterator == r_map.end()) { + NotFoundError(rItemName); + } return *(iterator->second); } @@ -179,7 +206,9 @@ namespace Kratos { SubRegistryItemType& r_map = GetSubRegistryItemMap(); auto iterator = r_map.find(rItemName); - KRATOS_ERROR_IF(iterator == r_map.end()) << "The RegistryItem " << this->Name() << " does not have an item with name " << rItemName << std::endl; + if (iterator == r_map.end()) { + NotFoundError(rItemName); + } r_map.erase(iterator); }