@@ -42,23 +42,24 @@ void PropertyTree::mergeSchema(const PropertyTree& schema)
4242 }
4343}
4444
45- bool PropertyTree::validate (std::vector<std::string>& errors, const std::string& path ) const
45+ void PropertyTree::validate () const
4646{
47- bool ok = true ;
4847 // run custom validators
4948 for (const auto & vfn : validators_)
50- {
51- if (!vfn (*this , errors, path))
52- ok = false ;
53- }
49+ vfn (*this );
50+
5451 // recurse children
5552 for (const auto & kv : children_)
5653 {
57- const std::string nextPath = path.empty () ? kv.first : path + " ." + kv.first ;
58- if (!kv.second .validate (errors, nextPath))
59- ok = false ;
54+ try
55+ {
56+ kv.second .validate ();
57+ }
58+ catch (...)
59+ {
60+ std::throw_with_nested (std::runtime_error (" Validation failed for property: " + kv.first ));
61+ }
6062 }
61- return ok;
6263}
6364
6465// / Add a custom validator for this node
@@ -184,22 +185,18 @@ YAML::Node PropertyTree::toYAML() const
184185 return value_;
185186}
186187
187- bool validateRequired (const PropertyTree& node, std::vector<std::string>& errors, const std::string& path )
188+ void validateRequired (const PropertyTree& node)
188189{
189190 auto req_attr = node.getAttribute (property_attribute::REQUIRED);
190191 if (req_attr && req_attr->as <bool >())
191192 {
192193 // if leaf node with no value or null
193194 if (!node.getValue () || node.getValue ().IsNull ())
194- {
195- errors.push_back (path + " : required property missing or null" );
196- return false ;
197- }
195+ std::throw_with_nested (std::runtime_error (" Required property missing or null" ));
198196 }
199- return true ;
200197}
201198
202- bool validateRange (const PropertyTree& node, std::vector<std::string>& errors, const std::string& path )
199+ void validateRange (const PropertyTree& node)
203200{
204201 auto min_attr = node.getAttribute (property_attribute::MINIMUM);
205202 auto max_attr = node.getAttribute (property_attribute::MAXIMUM);
@@ -210,15 +207,13 @@ bool validateRange(const PropertyTree& node, std::vector<std::string>& errors, c
210207 const auto val = node.getValue ().as <double >();
211208 if (val < minv || val > maxv)
212209 {
213- errors.push_back (path + " : value " + std::to_string (val) + " out of range [" + std::to_string (minv) + " ," +
214- std::to_string (maxv) + " ]" );
215- return false ;
210+ std::throw_with_nested (std::runtime_error (" Property value " + std::to_string (val) + " out of range [" +
211+ std::to_string (minv) + " ," + std::to_string (maxv) + " ]" ));
216212 }
217213 }
218- return true ;
219214}
220215
221- bool validateEnum (const PropertyTree& node, std::vector<std::string>& errors, const std::string& path )
216+ void validateEnum (const PropertyTree& node)
222217{
223218 auto enum_attr = node.getAttribute (property_attribute::ENUM);
224219 if (enum_attr.has_value () && enum_attr->IsSequence ())
@@ -227,12 +222,10 @@ bool validateEnum(const PropertyTree& node, std::vector<std::string>& errors, co
227222 for (const auto & v : enum_attr.value ())
228223 {
229224 if (v.as <std::string>() == val)
230- return true ;
225+ return ;
231226 }
232- errors.push_back (path + " : value '" + val + " ' not in enum list" );
233- return false ;
227+ std::throw_with_nested (std::runtime_error (" Property value '" + val + " ' not in enum list" ));
234228 }
235- return true ;
236229}
237230
238231} // namespace tesseract_common
0 commit comments