From 26cb1f18aa949710ddf0f2c0dff39fd3164e31c5 Mon Sep 17 00:00:00 2001 From: eZio Pan Date: Sun, 25 Feb 2024 17:04:09 +0800 Subject: [PATCH] let "MakeArray" print item name on error --- src/transform/make_field_array.rs | 5 +++-- src/transform/make_register_array.rs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/transform/make_field_array.rs b/src/transform/make_field_array.rs index 0698aa7..31dd54c 100644 --- a/src/transform/make_field_array.rs +++ b/src/transform/make_field_array.rs @@ -1,3 +1,4 @@ +use anyhow::bail; use log::*; use serde::{Deserialize, Serialize}; @@ -42,7 +43,7 @@ impl MakeFieldArray { .any(|i| matches!(i.bit_offset, BitOffset::Cursed(_))); if has_regular_bit_offset && has_cursed_bit_offset { - panic!("arrayize: items cannot mix bit_offset type") + bail!("arrayize: items {} cannot mix bit_offset type", to) } } @@ -58,7 +59,7 @@ impl MakeFieldArray { calc_array(items.iter().map(|x| x.bit_offset.min_offset()).collect()); if let Array::Cursed(_) = &array { if !self.allow_cursed { - panic!("arrayize: items are not evenly spaced. Set `allow_cursed: true` to allow this.") + bail!("arrayize: items {} are not evenly spaced. Set `allow_cursed: true` to allow this.", to) } } diff --git a/src/transform/make_register_array.rs b/src/transform/make_register_array.rs index b6f1fea..b8163a3 100644 --- a/src/transform/make_register_array.rs +++ b/src/transform/make_register_array.rs @@ -1,3 +1,4 @@ +use anyhow::bail; use log::*; use serde::{Deserialize, Serialize}; @@ -41,7 +42,7 @@ impl MakeRegisterArray { let (offset, array) = calc_array(items.iter().map(|x| x.byte_offset).collect()); if let Array::Cursed(_) = &array { if !self.allow_cursed { - panic!("arrayize: items are not evenly spaced. Set `allow_cursed: true` to allow this.") + bail!("arrayize: items {} are not evenly spaced. Set `allow_cursed: true` to allow this.", to); } }