Skip to content

Commit 7d93b17

Browse files
authored
Merge #1944 Improve the exception msg in config
This PR improves the exception message in the config parse. Related PR: #1944
2 parents f4c2992 + 3cc6469 commit 7d93b17

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

core/config/config.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -22,9 +22,13 @@ deferred_factory_parameter<gko::LinOpFactory> parse(const pnode& config,
2222
const type_descriptor& td)
2323
{
2424
if (auto& obj = config.get("type")) {
25-
auto func = detail::registry_accessor::get_build_map(context).at(
26-
obj.get_string());
27-
return func(config, context, td);
25+
const auto& build_map =
26+
detail::registry_accessor::get_build_map(context);
27+
auto search = build_map.find(obj.get_string());
28+
if (search == build_map.end()) {
29+
GKO_INVALID_CONFIG_VALUE("type", obj.get_string());
30+
}
31+
return search->second(config, context, td);
2832
}
2933
GKO_MISSING_CONFIG_ENTRY("type");
3034
}

core/test/config/config.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ TEST_F(Config, GenerateObjectWithCustomBuild)
124124
}
125125

126126

127+
TEST_F(Config, ThrowWhenKeyIsInvalidInType)
128+
{
129+
auto reg = registry();
130+
pnode p{{{"type", pnode{"Invalid"}}}};
131+
132+
ASSERT_THROW(parse(p, reg), gko::InvalidStateError);
133+
}
134+
135+
127136
TEST_F(Config, ThrowWhenKeyIsInvalidInCriterion)
128137
{
129138
auto reg = registry();

0 commit comments

Comments
 (0)