Better error message for missing form properties

dependabot/npm_and_yarn/Src/WebController/UI/websocket-extensions-0.1.4
Grzegorz Rychlik 2020-02-18 16:09:28 +01:00
parent 3e9ca203c4
commit 22b15fc6e1
1 changed files with 3 additions and 3 deletions

View File

@ -160,8 +160,6 @@ namespace MWR::C3::Linter
FormElement::FormElement(json& definition) : FormElement::FormElement(json& definition) :
m_Definition(definition) m_Definition(definition)
{ {
if (!m_Definition.contains("name"))
throw std::invalid_argument{ "Form element must contain 'name' property." };
} }
/// Generate FormElement::Type to_json and from_json fuctions to enable serialization /// Generate FormElement::Type to_json and from_json fuctions to enable serialization
@ -190,8 +188,10 @@ namespace MWR::C3::Linter
{ {
if (!element.is_object()) if (!element.is_object())
throw std::invalid_argument { "Form element must be a json object." }; throw std::invalid_argument { "Form element must be a json object." };
if (!element.contains("name"))
throw std::invalid_argument{ "Form element must contain 'name' property. \nInvalid element:\n" + element.dump(4) };
if (!element.contains("type")) if (!element.contains("type"))
throw std::invalid_argument{ "Form element must contain 'type' property." }; throw std::invalid_argument{ "Form element '" + element["name"].get<std::string>() + "' must contain 'type' property." };
switch (element["type"].get<FormElement::Type>()) switch (element["type"].get<FormElement::Type>())
{ {