Skip to content

Commit

Permalink
[Status] In case of panicking, a special cleanup should take place
Browse files Browse the repository at this point in the history
  • Loading branch information
Laury Bueno committed Nov 12, 2020
1 parent e0ae759 commit fa3282b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"
"log"
"runtime/debug"
"sort"
"time"

Expand Down Expand Up @@ -87,8 +88,15 @@ func runTop(cmd *cobra.Command, args []string) {
}
}

func panicCleanUp() {
if r := recover(); r != nil {
ui.Close()
fmt.Printf("Something went wrong. Here's what we know: %#v", string(debug.Stack()))
}
}

func prepareDataTable() {
defer ui.Close()
defer panicCleanUp()

for {
pods := getPodsData()
Expand Down Expand Up @@ -152,7 +160,7 @@ func updateInterface() {
}

func updateGauge(current, total int) {
defer ui.Close()
defer panicCleanUp()

if gauge == nil {
gauge = widgets.NewGauge()
Expand Down

0 comments on commit fa3282b

Please sign in to comment.