Skip to content

Commit

Permalink
added error for when no parameter fits
Browse files Browse the repository at this point in the history
- added check to applyParameter that throws an error if the provided param does not match any known param
- added to applyParameter unit test to ensure an error is thrown

closes idaholab#27556
  • Loading branch information
DanielYankura committed Jan 22, 2025
1 parent bf7a391 commit e642729
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions framework/src/utils/InputParameters.C
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "MultiMooseEnum.h"
#include "ExecFlagEnum.h"
#include "MooseObject.h"
#include "FEProblem.h"

#include "libmesh/utility.h"
#include "libmesh/simple_range.h"
Expand Down Expand Up @@ -1156,6 +1157,8 @@ InputParameters::applyParameter(const InputParameters & common,
// the parameter in the action
at(local_name)._hit_node = common.getHitNode(common_name);
}
else if (!local_exist && !common_exist)
mooseError("Attempted to apply invalid parameter \"", common_name, "\"");

// Enable deprecated message printing
_show_deprecated_message = true;
Expand Down
3 changes: 3 additions & 0 deletions unit/src/InputParametersTest.C
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ TEST(InputParametersTest, applyParameter)
p2.set<MultiMooseEnum>("enum") = "bar";
p1.applyParameter(p2, "enum");
EXPECT_TRUE(p1.get<MultiMooseEnum>("enum").contains("bar"));

// applyParameter should throw error if input parameter doesn't match any valid parameters
EXPECT_THROW(p1.applyParameter(p2, "invalid_param"), std::exception);
}

TEST(InputParametersTest, applyParametersVector)
Expand Down

0 comments on commit e642729

Please sign in to comment.