diff --git a/core/config/config.cpp b/core/config/config.cpp index adb47e5ef75..ffe6a11da9d 100644 --- a/core/config/config.cpp +++ b/core/config/config.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors +// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors // // SPDX-License-Identifier: BSD-3-Clause @@ -22,9 +22,13 @@ deferred_factory_parameter parse(const pnode& config, const type_descriptor& td) { if (auto& obj = config.get("type")) { - auto func = detail::registry_accessor::get_build_map(context).at( - obj.get_string()); - return func(config, context, td); + const auto& build_map = + detail::registry_accessor::get_build_map(context); + auto search = build_map.find(obj.get_string()); + if (search != build_map.end()) { + GKO_INVALID_CONFIG_VALUE("type", obj.get_string()); + } + return search->second(config, context, td); } GKO_MISSING_CONFIG_ENTRY("type"); } diff --git a/core/test/config/config.cpp b/core/test/config/config.cpp index 9922c879895..07640cb391d 100644 --- a/core/test/config/config.cpp +++ b/core/test/config/config.cpp @@ -124,6 +124,15 @@ TEST_F(Config, GenerateObjectWithCustomBuild) } +TEST_F(Config, ThrowWhenKeyIsInvalidInType) +{ + auto reg = registry(); + pnode p{{{"type", pnode{"Invalid"}}}}; + + ASSERT_THROW(parse(p, reg), gko::InvalidStateError); +} + + TEST_F(Config, ThrowWhenKeyIsInvalidInCriterion) { auto reg = registry();