diff --git a/.gitignore b/.gitignore index 26a0769..08c1263 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ [._]*.sw[a-p] *.org *.rs.bk -target \ No newline at end of file +target +.DS_Store diff --git a/src/generate/block.rs b/src/generate/block.rs index 3a7b566..a9f6ac6 100644 --- a/src/generate/block.rs +++ b/src/generate/block.rs @@ -1,4 +1,4 @@ -use anyhow::Result; +use anyhow::{anyhow, bail, Result}; use proc_macro2::TokenStream; use proc_macro2::{Ident, Span}; use quote::quote; @@ -23,7 +23,10 @@ pub fn render(opts: &super::Options, ir: &IR, b: &Block, path: &str) -> Result { let reg_ty = if let Some(fieldset_path) = &r.fieldset { - let _f = ir.fieldsets.get(fieldset_path).unwrap(); + let _f = ir + .fieldsets + .get(fieldset_path) + .ok_or_else(|| anyhow!("Couldn't find fieldset: {fieldset_path}"))?; util::relative_path(fieldset_path, path) } else { match r.bit_size { @@ -31,7 +34,7 @@ pub fn render(opts: &super::Options, ir: &IR, b: &Block, path: &str) -> Result quote!(u16), 32 => quote!(u32), 64 => quote!(u64), - _ => panic!("Invalid register bit size {}", r.bit_size), + _ => bail!("Invalid register bit size {}", r.bit_size), } }; @@ -64,7 +67,11 @@ pub fn render(opts: &super::Options, ir: &IR, b: &Block, path: &str) -> Result { let block_path = &b.block; - let _b2 = ir.blocks.get(block_path).unwrap(); + let _b2 = ir + .blocks + .get(block_path) + .ok_or_else(|| anyhow!("Couldn't find block: {block_path}"))?; + let ty = util::relative_path(block_path, path); if let Some(array) = &i.array { let (len, offs_expr) = super::process_array(array); diff --git a/src/generate/device.rs b/src/generate/device.rs index d5eb623..bed4192 100644 --- a/src/generate/device.rs +++ b/src/generate/device.rs @@ -12,7 +12,7 @@ use super::{sorted, with_defmt_cfg_attr}; pub fn render_device_x(_ir: &IR, d: &Device) -> Result { let mut device_x = String::new(); for i in sorted(&d.interrupts, |i| i.value) { - writeln!(&mut device_x, "PROVIDE({} = DefaultHandler);", i.name).unwrap(); + writeln!(&mut device_x, "PROVIDE({} = DefaultHandler);", i.name)?; } Ok(device_x) } diff --git a/src/generate/enumm.rs b/src/generate/enumm.rs index 937ef44..36d782f 100644 --- a/src/generate/enumm.rs +++ b/src/generate/enumm.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use anyhow::Result; +use anyhow::{bail, Result}; use proc_macro2::TokenStream; use proc_macro2::{Ident, Span}; use quote::quote; @@ -26,7 +26,7 @@ pub fn render(opts: &super::Options, _ir: &IR, e: &Enum, path: &str) -> Result quote!(u16), 17..=32 => quote!(u32), 33..=64 => quote!(u64), - _ => panic!("Invalid bit_size {}", e.bit_size), + _ => bail!("Invalid bit_size {}", e.bit_size), }; let (_, name) = super::split_path(path);