From 0b9d3c0a009c68ae726e2fa417a60619a011beca Mon Sep 17 00:00:00 2001 From: Alain Emilia Anna Zscheile Date: Mon, 2 Dec 2024 23:08:50 +0100 Subject: [PATCH] fix(specctra/design): invalid references shouldn't panic during serialization --- src/specctra/design.rs | 20 ++++++++++++++++++-- src/specctra/mod.rs | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/specctra/design.rs b/src/specctra/design.rs index ae4b19f..417eece 100644 --- a/src/specctra/design.rs +++ b/src/specctra/design.rs @@ -135,7 +135,15 @@ impl SpecctraDesign { path: structure::Path { layer: mesadata .layer_layername(primitive.layer()) - .unwrap() + .ok_or_else(|| { + std::io::Error::new( + std::io::ErrorKind::InvalidData, + format!( + "tried to reference invalid primitive layer {}", + primitive.layer() + ), + ) + })? .to_owned(), width: primitive.width(), coords, @@ -148,7 +156,15 @@ impl SpecctraDesign { net_outs.insert( net, structure::NetOut { - name: mesadata.net_netname(net).unwrap().to_owned(), + name: mesadata + .net_netname(net) + .ok_or_else(|| { + std::io::Error::new( + std::io::ErrorKind::InvalidData, + format!("tried to reference invalid net ID {}", net), + ) + })? + .to_owned(), wire: vec![wire], via: Vec::new(), }, diff --git a/src/specctra/mod.rs b/src/specctra/mod.rs index 86e4cc6..f8e7b7f 100644 --- a/src/specctra/mod.rs +++ b/src/specctra/mod.rs @@ -1,5 +1,7 @@ //! Module containing the informations about handling the Specctra //! based file format, and parsing it into Topola's objects +#![forbid(unused_must_use)] +#![forbid(clippy::panic_in_result_fn, clippy::unwrap_in_result)] mod common; pub mod design;