Skip to content

Commit f9cde0a

Browse files
sebastien-rossetdominikh
authored andcommitted
go/ir: recognize functions in go.uber.org/zap that exit the process or panic
Closes: gh-1109 [via git-merge-pr] (cherry picked from commit 8d6bc3a)
1 parent f897f3c commit f9cde0a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

go/ir/exits.go

+26
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@ func (b *builder) buildExits(fn *Function) {
1919
fn.NoReturn = AlwaysUnwinds
2020
return
2121
}
22+
case "go.uber.org/zap":
23+
switch obj.(*types.Func).FullName() {
24+
case "(*go.uber.org/zap.Logger).Fatal",
25+
"(*go.uber.org/zap.SugaredLogger).Fatal",
26+
"(*go.uber.org/zap.SugaredLogger).Fatalw",
27+
"(*go.uber.org/zap.SugaredLogger).Fatalf":
28+
// Technically, this method does not unconditionally exit
29+
// the process. It dynamically calls a function stored in
30+
// the logger. If the function is nil, it defaults to
31+
// os.Exit.
32+
//
33+
// The main intent of this method is to terminate the
34+
// process, and that's what the vast majority of people
35+
// will use it for. We'll happily accept some false
36+
// negatives to avoid a lot of false positives.
37+
fn.NoReturn = AlwaysExits
38+
case "(*go.uber.org/zap.Logger).Panic",
39+
"(*go.uber.org/zap.SugaredLogger).Panicw",
40+
"(*go.uber.org/zap.SugaredLogger).Panicf":
41+
fn.NoReturn = AlwaysUnwinds
42+
return
43+
case "(*go.uber.org/zap.Logger).DPanic",
44+
"(*go.uber.org/zap.SugaredLogger).DPanicf",
45+
"(*go.uber.org/zap.SugaredLogger).DPanicw":
46+
// These methods will only panic in development.
47+
}
2248
case "github.com/sirupsen/logrus":
2349
switch obj.(*types.Func).FullName() {
2450
case "(*github.com/sirupsen/logrus.Logger).Exit":

0 commit comments

Comments
 (0)