Skip to content

Commit 675e73b

Browse files
authored
more resource validation (#1097)
1 parent 45128ed commit 675e73b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/amr/resources_manager/resources_manager.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,11 @@ namespace amr
322322
auto getIDsList(auto&&... keys) const
323323
{
324324
auto const Fn = [&](auto& key) {
325+
if (key.empty())
326+
throw std::runtime_error("Resource Manager key cannot be empty");
325327
if (auto const id = getID(key))
326328
return *id;
327-
throw std::runtime_error("bad key");
329+
throw std::runtime_error("Resource Manager has no key: " + key);
328330
};
329331
return std::array{Fn(keys)...};
330332
}
@@ -508,6 +510,9 @@ namespace amr
508510
{
509511
using ResourcesResolver_t = ResourceResolver<This, ResourcesView>;
510512

513+
if (view.name().empty())
514+
throw std::runtime_error("Resource Manager key cannot be empty");
515+
511516
if (nameToResourceInfo_.count(view.name()) == 0)
512517
{
513518
ResourcesInfo info;
@@ -530,6 +535,9 @@ namespace amr
530535
using ResourceResolver_t = ResourceResolver<This, ResourcesView>;
531536
using ResourcesType = ResourceResolver_t::type;
532537

538+
if (obj.name().empty())
539+
throw std::runtime_error("Resource Manager key cannot be empty");
540+
533541
auto const& resourceInfoIt = nameToResourceInfo_.find(obj.name());
534542
if (resourceInfoIt == nameToResourceInfo_.end())
535543
throw std::runtime_error("Resources not found !");
@@ -540,6 +548,9 @@ namespace amr
540548
template<typename ResourcesView>
541549
void unsetResourcesInternal_(ResourcesView& obj) const
542550
{
551+
if (obj.name().empty())
552+
throw std::runtime_error("Resource Manager key cannot be empty");
553+
543554
auto const& resourceInfoIt = nameToResourceInfo_.find(obj.name());
544555
if (resourceInfoIt == nameToResourceInfo_.end())
545556
throw std::runtime_error("Resources not found !");
@@ -554,7 +565,11 @@ namespace amr
554565
void allocate_(ResourcesView const& obj, SAMRAI::hier::Patch& patch,
555566
double const allocateTime) const
556567
{
557-
std::string const& resourcesName = obj.name();
568+
std::string const& resourcesName = obj.name();
569+
570+
if (obj.name().empty())
571+
throw std::runtime_error("Resource Manager key cannot be empty");
572+
558573
auto const& resourceVariablesInfo = nameToResourceInfo_.find(resourcesName);
559574
if (resourceVariablesInfo != nameToResourceInfo_.end())
560575
{

0 commit comments

Comments
 (0)