Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the logging of stacks in errors an opt-in behavior #4826

Merged
merged 2 commits into from
Apr 19, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions go/vt/vterrors/vterrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,20 @@
package vterrors

import (
"flag"
"fmt"
"io"

"golang.org/x/net/context"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
)

var logErrStacks bool

func init() {
flag.BoolVar(&logErrStacks, "logerrstacks", false, "log stack traces in errors")
}

// New returns an error with the supplied message.
// New also records the stack trace at the point it was called.
func New(code vtrpcpb.Code, message string) error {
Expand Down Expand Up @@ -122,7 +129,9 @@ func (f *fundamental) Format(s fmt.State, verb rune) {
case 'v':
panicIfError(io.WriteString(s, "Code: "+f.code.String()+"\n"))
panicIfError(io.WriteString(s, f.msg+"\n"))
f.stack.Format(s, verb)
if logErrStacks {
f.stack.Format(s, verb)
}
return
case 's':
panicIfError(io.WriteString(s, f.msg))
Expand Down Expand Up @@ -198,7 +207,9 @@ func (w *wrapping) Format(s fmt.State, verb rune) {
if rune('v') == verb {
panicIfError(fmt.Fprintf(s, "%v\n", w.Cause()))
panicIfError(io.WriteString(s, w.msg))
w.stack.Format(s, verb)
if logErrStacks {
w.stack.Format(s, verb)
}
return
}

Expand Down