Skip to content

Commit 0c421dc

Browse files
authored
Merge pull request #28 from eZioPan/make_array-err
let "MakeArray" print item name on error
2 parents 3875f77 + 26cb1f1 commit 0c421dc

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/transform/make_field_array.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::bail;
12
use log::*;
23
use serde::{Deserialize, Serialize};
34

@@ -42,7 +43,7 @@ impl MakeFieldArray {
4243
.any(|i| matches!(i.bit_offset, BitOffset::Cursed(_)));
4344

4445
if has_regular_bit_offset && has_cursed_bit_offset {
45-
panic!("arrayize: items cannot mix bit_offset type")
46+
bail!("arrayize: items {} cannot mix bit_offset type", to)
4647
}
4748
}
4849

@@ -58,7 +59,7 @@ impl MakeFieldArray {
5859
calc_array(items.iter().map(|x| x.bit_offset.min_offset()).collect());
5960
if let Array::Cursed(_) = &array {
6061
if !self.allow_cursed {
61-
panic!("arrayize: items are not evenly spaced. Set `allow_cursed: true` to allow this.")
62+
bail!("arrayize: items {} are not evenly spaced. Set `allow_cursed: true` to allow this.", to)
6263
}
6364
}
6465

src/transform/make_register_array.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::bail;
12
use log::*;
23
use serde::{Deserialize, Serialize};
34

@@ -41,7 +42,7 @@ impl MakeRegisterArray {
4142
let (offset, array) = calc_array(items.iter().map(|x| x.byte_offset).collect());
4243
if let Array::Cursed(_) = &array {
4344
if !self.allow_cursed {
44-
panic!("arrayize: items are not evenly spaced. Set `allow_cursed: true` to allow this.")
45+
bail!("arrayize: items {} are not evenly spaced. Set `allow_cursed: true` to allow this.", to);
4546
}
4647
}
4748

0 commit comments

Comments
 (0)