Skip to content

Commit

Permalink
Replace unwrap() with alternatives to avoid panics
Browse files Browse the repository at this point in the history
  • Loading branch information
dilyn-corner committed Jan 13, 2023
1 parent 627ad51 commit 3d26ef9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
8 changes: 4 additions & 4 deletions esp32-wroom-rp/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl NinaConcreteParam for NinaByteParam {

fn from_bytes(bytes: &[u8]) -> Self {
let mut data_as_bytes: Vec<u8, 1> = Vec::new();
data_as_bytes.extend_from_slice(bytes).ok().unwrap();
data_as_bytes.extend_from_slice(bytes).unwrap_or_default();
Self {
length: data_as_bytes.len() as u8,
data: data_as_bytes,
Expand Down Expand Up @@ -240,7 +240,7 @@ impl NinaConcreteParam for NinaWordParam {

fn from_bytes(bytes: &[u8]) -> Self {
let mut data_as_bytes: Vec<u8, 2> = Vec::new();
data_as_bytes.extend_from_slice(bytes).ok().unwrap();
data_as_bytes.extend_from_slice(bytes).unwrap_or_default();
Self {
length: data_as_bytes.len() as u8,
data: data_as_bytes,
Expand Down Expand Up @@ -273,7 +273,7 @@ impl NinaConcreteParam for NinaSmallArrayParam {

fn from_bytes(bytes: &[u8]) -> Self {
let mut data_as_bytes: Vec<u8, MAX_NINA_PARAM_LENGTH> = Vec::new();
data_as_bytes.extend_from_slice(bytes).ok().unwrap();
data_as_bytes.extend_from_slice(bytes).unwrap_or_default();
Self {
length: data_as_bytes.len() as u8,
data: data_as_bytes,
Expand Down Expand Up @@ -306,7 +306,7 @@ impl NinaConcreteParam for NinaLargeArrayParam {

fn from_bytes(bytes: &[u8]) -> Self {
let mut data_as_bytes: Vec<u8, MAX_NINA_PARAM_LENGTH> = Vec::new();
data_as_bytes.extend_from_slice(bytes).ok().unwrap();
data_as_bytes.extend_from_slice(bytes).unwrap_or_default();
Self {
length: data_as_bytes.len() as u16,
data: data_as_bytes,
Expand Down
2 changes: 1 addition & 1 deletion esp32-wroom-rp/src/protocol/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Operation<NinaAbstractParam> {
// on the data bus.
pub fn param(mut self, param: NinaAbstractParam) -> Self {
// FIXME: Vec::push() will return T when it is full, handle this gracefully
self.params.push(param).ok().unwrap();
self.params.push(param).unwrap_or(());
self
}
}
1 change: 0 additions & 1 deletion esp32-wroom-rp/src/tcp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ where
ip = self
.protocol_handler
.resolve(hostname.as_str())
.ok()
.unwrap_or_default();
}

Expand Down

0 comments on commit 3d26ef9

Please sign in to comment.