dnetview: fix bugs in error handling

* only render node_info if our data is not empty
* handle when msgs are Null
* print unexpected data to string
This commit is contained in:
lunar-mining
2022-05-04 08:49:16 +02:00
parent 015f3ddefc
commit 4edebb22ab
2 changed files with 22 additions and 14 deletions

View File

@@ -10,7 +10,7 @@ pub enum DnetViewError {
#[error("Failed to find ID at current index")]
NoIdAtIndex,
#[error("Found unexpected data in View")]
UnexpectedData,
UnexpectedData(String),
#[error("Message log does not contain ID")]
CannotFindId,
#[error("ID does not return a selectable object")]

View File

@@ -95,17 +95,22 @@ impl View {
// remove any duplicates
id_list.dedup();
// get the id at the current index
match self.active_ids.state.selected() {
Some(i) => match id_list.get(i) {
Some(i) => {
self.render_info(f, slice.clone(), i.to_string())?;
Ok(())
}
None => Err(DnetViewError::NoIdAtIndex),
},
// nothing is selected right now
None => Ok(()),
if id_list.is_empty() {
// we have not received any data
Ok(())
} else {
// get the id at the current index
match self.active_ids.state.selected() {
Some(i) => match id_list.get(i) {
Some(i) => {
self.render_info(f, slice.clone(), i.to_string())?;
Ok(())
}
None => return Err(DnetViewError::NoIdAtIndex),
},
// nothing is selected right now
None => Ok(()),
}
}
}
@@ -150,7 +155,10 @@ impl View {
);
info.push(msg);
}
_ => return Err(DnetViewError::UnexpectedData),
"Null" => {
// Empty msg log. Do nothing
}
data => return Err(DnetViewError::UnexpectedData(data.to_string())),
}
let lines = vec![Spans::from(info)];
@@ -206,7 +214,7 @@ impl View {
Spans::from(Span::styled(format!("R: {}", v), style));
spans.push(msg_log);
}
_ => return Err(DnetViewError::UnexpectedData),
data => return Err(DnetViewError::UnexpectedData(data.to_string())),
}
}
}