Simply panic for failfast

The old contract library tried to be glog-friendly in its failfast behavior.
It turns out glog seldom does the right thing when goroutines are involved
(which, as of last sprint, they now are).  We already had issues with stacks
not getting printed when --logtostderr was turned on, and the code tried
to work around this; but this still didn't work for the goroutines case.

All of this seems like way too much cleverness.  Let's just use Go panics.
This commit is contained in:
joeduffy 2017-06-27 11:12:06 -07:00
parent 3c73b32391
commit 23045c5792

View file

@ -3,25 +3,10 @@
package contract
import (
"flag"
"fmt"
"os"
"runtime/debug"
"github.com/golang/glog"
)
// failfast logs and panics the process in a way that is friendly to debugging.
func failfast(msg string) {
v := flag.Lookup("logtostderr").Value
if g, isgettable := v.(flag.Getter); isgettable {
if enabled := g.Get().(bool); enabled {
// Print the stack to stderr anytime glog verbose logging is enabled, since glog won't.
if _, err := fmt.Fprintf(os.Stderr, "fatal: %v\n", msg); err != nil {
glog.Infof("Printing fatal error failed with error: %v", err)
}
debug.PrintStack()
}
}
glog.Fatal(msg)
panic(fmt.Sprintf("fatal: %v", msg))
}