From 43d69cb1aa86e699ee70af831a0cee43a591a84f Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 18 Jul 2019 13:57:51 +0200 Subject: [PATCH] macro: more error handling improvements Signed-off-by: Wolfgang Bumiller --- proxmox-api-macro/src/api_macro.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/proxmox-api-macro/src/api_macro.rs b/proxmox-api-macro/src/api_macro.rs index 4b7ad379..388b09ae 100644 --- a/proxmox-api-macro/src/api_macro.rs +++ b/proxmox-api-macro/src/api_macro.rs @@ -535,7 +535,9 @@ fn handle_named_struct_fields( let def = field_def .remove(&name_str) - .ok_or_else(|| format_err!("missing field in definition: '{}'", name_str))? + .ok_or_else(|| { + c_format_err!(name.span(), "missing field in definition: '{}'", name_str) + })? .expect_object()?; let def = ParameterDefinition::from_object(def)?; @@ -544,14 +546,19 @@ fn handle_named_struct_fields( if !field_def.is_empty() { // once SliceConcatExt is stable we can join(",") on the fields... + let mut span = None; let mut missing = String::new(); for key in field_def.keys() { if !missing.is_empty() { missing.push_str(", "); } + if span.is_none() { + span = Some(key.span()); + } missing.push_str(key.as_str()); } - bail!( + c_bail!( + span.unwrap(), "the following struct fields are not handled in the api definition: {}", missing );