From a53e8c5e82e83596f6e470bdae4c7656f6b5e52b Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 8 Aug 2019 11:17:37 +0200 Subject: [PATCH] macro: make sure errors are separated Signed-off-by: Wolfgang Bumiller --- proxmox-api-macro/src/api_macro.rs | 39 ++++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/proxmox-api-macro/src/api_macro.rs b/proxmox-api-macro/src/api_macro.rs index d4f9e9de..186ab00b 100644 --- a/proxmox-api-macro/src/api_macro.rs +++ b/proxmox-api-macro/src/api_macro.rs @@ -667,8 +667,8 @@ fn struct_fields_impl_verify(span: Span, fields: &[StructField]) -> Result let value = #value; if !::proxmox::api::verify::TestMinMax::test_minimum(&self.#field_access, &value) { - error_string.push_str( - &format!("field {} out of range, must be >= {}", #field_str, value) + error_list.push( + format!("field {} out of range, must be >= {}", #field_str, value) ); } }); @@ -678,8 +678,8 @@ fn struct_fields_impl_verify(span: Span, fields: &[StructField]) -> Result let value = #value; if !::proxmox::api::verify::TestMinMax::test_maximum(&self.#field_access, &value) { - error_string.push_str( - &format!("field {} out of range, must be <= {}", #field_str, value) + error_list.push( + format!("field {} out of range, must be <= {}", #field_str, value) ); } }); @@ -692,8 +692,8 @@ fn struct_fields_impl_verify(span: Span, fields: &[StructField]) -> Result= {} characters", #field_str, value) + error_list.push( + format!("field {} too short, must be >= {} characters", #field_str, value) ); } }); @@ -706,8 +706,8 @@ fn struct_fields_impl_verify(span: Span, fields: &[StructField]) -> Result Result if !#value::verify(&self.#field_access) { - error_string.push_str( - &format!("field {} does not match format {}", #field_str, #value::NAME) + error_list.push( + format!("field {} does not match format {}", #field_str, #value::NAME) ); } }); @@ -731,7 +731,7 @@ fn struct_fields_impl_verify(span: Span, fields: &[StructField]) -> Result Result body.extend(quote_spanned! { value.span() => if !#regex.is_match(&self.#field_access) { - error_string.push_str( - &format!("field {} does not match the allowed pattern", #field_str) + error_list.push( + format!("field {} does not match the allowed pattern", #field_str) ); } }), @@ -752,7 +752,7 @@ fn struct_fields_impl_verify(span: Span, fields: &[StructField]) -> Result if let Err(err) = #value(&self.#field_access) { - error_string.push_str(&err.to_string()); + error_list.push(err.to_string()); } }); } @@ -761,9 +761,16 @@ fn struct_fields_impl_verify(span: Span, fields: &[StructField]) -> Result #[allow(unused_mut)] - let mut error_string = String::new(); + let mut error_list: Vec = Vec::new(); #body - if !error_string.is_empty() { + if !error_list.is_empty() { + let mut error_string = String::new(); + for e in error_list.iter() { + if !error_string.is_empty() { + error_string.push_str("\n"); + } + error_string.push_str(&e); + } return Err(::failure::format_err!("{}", error_string)); } };