mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
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:
@@ -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")]
|
||||
|
||||
@@ -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())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user