From e64272957776818595538ae7880d56b56c1a8f37 Mon Sep 17 00:00:00 2001 From: Daniel Yankura Date: Wed, 22 Jan 2025 16:06:08 -0700 Subject: [PATCH] added error for when no parameter fits - 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 #27556 --- framework/src/utils/InputParameters.C | 3 +++ unit/src/InputParametersTest.C | 3 +++ 2 files changed, 6 insertions(+) diff --git a/framework/src/utils/InputParameters.C b/framework/src/utils/InputParameters.C index 6ab5b6697b15..f3756056525d 100644 --- a/framework/src/utils/InputParameters.C +++ b/framework/src/utils/InputParameters.C @@ -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" @@ -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; diff --git a/unit/src/InputParametersTest.C b/unit/src/InputParametersTest.C index 7558fb479881..6c507a8ef59d 100644 --- a/unit/src/InputParametersTest.C +++ b/unit/src/InputParametersTest.C @@ -182,6 +182,9 @@ TEST(InputParametersTest, applyParameter) p2.set("enum") = "bar"; p1.applyParameter(p2, "enum"); EXPECT_TRUE(p1.get("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)