Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Show stack-trace from panic in weave-npc
Browse files Browse the repository at this point in the history
Rather than exiting silently, fetch the stack trace and print that
for the user to understand what happened.

Exit via existing fatal-error code.
  • Loading branch information
bboreham committed Aug 5, 2020
1 parent 23a8270 commit 4795ba5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion prog/weave-npc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"context"
"fmt"
"os"
"os/signal"
goruntime "runtime"
"syscall"

"github.com/coreos/go-iptables/iptables"
Expand Down Expand Up @@ -218,7 +220,9 @@ func hCtx() context.Context {

func stopOnPanicRecover() {
if r := recover(); r != nil {
os.Exit(1)
buf := make([]byte, 1<<20)
stacklen := goruntime.Stack(buf, false)
handleFatal(fmt.Errorf("panic: %v \n%s", r, buf[:stacklen]))
}
}

Expand Down

0 comments on commit 4795ba5

Please sign in to comment.