168{
169 auto result = string_to_enum_case_insensitive<EnumType>(str);
170 if (!result.has_value()) {
171 std::string error_msg = "Invalid enum value: '" + std::string(str) + "'";
172 if (!context.empty()) {
173 error_msg += " for " + std::string(context);
174 }
175
176 error_msg += ". Valid values are: ";
177 auto names = get_enum_names_lowercase<EnumType>();
178 for (size_t i = 0; i < names.size(); ++i) {
179 if (i > 0)
180 error_msg += ", ";
181 error_msg += names[i];
182 }
183
184 throw std::invalid_argument(error_msg);
185 }
186 return *result;
187}