Fix runtime panics being suppressed
fatalLog was matching runtime errors, and essentially hiding them.
Test: m blueprint_tools
Change-Id: Ib48e7e142fc096998bc14b21fb717392adcff0ec
diff --git a/ui/logger/logger.go b/ui/logger/logger.go
index c763e50..58890e9 100644
--- a/ui/logger/logger.go
+++ b/ui/logger/logger.go
@@ -73,7 +73,9 @@
}
// fatalLog is the type used when Fatal[f|ln]
-type fatalLog error
+type fatalLog struct {
+ error
+}
func fileRotation(from, baseName, ext string, cur, max int) error {
newName := baseName + "." + strconv.Itoa(cur) + ext
@@ -273,7 +275,7 @@
func (s *stdLogger) Fatal(v ...interface{}) {
output := fmt.Sprint(v...)
s.Output(2, output)
- panic(fatalLog(errors.New(output)))
+ panic(fatalLog{errors.New(output)})
}
// Fatalf is equivalent to Printf() followed by a call to panic() that
@@ -281,7 +283,7 @@
func (s *stdLogger) Fatalf(format string, v ...interface{}) {
output := fmt.Sprintf(format, v...)
s.Output(2, output)
- panic(fatalLog(errors.New(output)))
+ panic(fatalLog{errors.New(output)})
}
// Fatalln is equivalent to Println() followed by a call to panic() that
@@ -289,7 +291,7 @@
func (s *stdLogger) Fatalln(v ...interface{}) {
output := fmt.Sprintln(v...)
s.Output(2, output)
- panic(fatalLog(errors.New(output)))
+ panic(fatalLog{errors.New(output)})
}
// Panic is equivalent to Print() followed by a call to panic().
diff --git a/ui/logger/logger_test.go b/ui/logger/logger_test.go
index bdf0231..044e6f0 100644
--- a/ui/logger/logger_test.go
+++ b/ui/logger/logger_test.go
@@ -196,3 +196,17 @@
log.Panic("Test")
t.Errorf("Should not get here")
}
+
+func TestRuntimePanic(t *testing.T) {
+ defer func() {
+ if p := recover(); p == nil {
+ t.Errorf("Panic not thrown")
+ }
+ }()
+ defer Recover(func(err error) {
+ t.Errorf("Recover function should not be called")
+ })
+ var i *int
+ *i = 0
+ t.Errorf("Should not get here")
+}