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