fix: out of bounds error, closes [#8]
use .is_some() and if let Some() to make sure that container indexes are still valid, without can cause out of bounds issue due to docker update frequencies
This commit is contained in:
+3
-1
@@ -304,10 +304,12 @@ impl AppData {
|
|||||||
if self.containers.state.selected().is_some() {
|
if self.containers.state.selected().is_some() {
|
||||||
self.containers.previous();
|
self.containers.previous();
|
||||||
}
|
}
|
||||||
// docker rm -f $(docker ps -aq) will cause this to crash
|
// Check is some, else can cause out of bounds error, if containers get removed before a docker update
|
||||||
|
if self.containers.items.get(index).is_some() {
|
||||||
self.containers.items.remove(index);
|
self.containers.items.remove(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for i in containers.iter() {
|
for i in containers.iter() {
|
||||||
if let Some(id) = i.id.as_ref() {
|
if let Some(id) = i.id.as_ref() {
|
||||||
|
|||||||
@@ -265,7 +265,10 @@ pub fn draw_chart<B: Backend>(
|
|||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||||
.split(area);
|
.split(area);
|
||||||
let (cpu, mem) = app_data.lock().containers.items[index].get_chart_data();
|
|
||||||
|
// Check is some, else can cause out of bounds error, if containers get removed before a docker update
|
||||||
|
if let Some(data) = app_data.lock().containers.items.get(index) {
|
||||||
|
let (cpu, mem) = data.get_chart_data();
|
||||||
|
|
||||||
let cpu_dataset = vec![Dataset::default()
|
let cpu_dataset = vec![Dataset::default()
|
||||||
.marker(symbols::Marker::Dot)
|
.marker(symbols::Marker::Dot)
|
||||||
@@ -297,6 +300,7 @@ pub fn draw_chart<B: Backend>(
|
|||||||
f.render_widget(mem_chart, area[1]);
|
f.render_widget(mem_chart, area[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Create charts
|
/// Create charts
|
||||||
fn make_chart<T: Stats + Display>(
|
fn make_chart<T: Stats + Display>(
|
||||||
|
|||||||
Reference in New Issue
Block a user