-
Notifications
You must be signed in to change notification settings - Fork 490
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
terror: print the stack in terror.Log() #803
Conversation
In TiDB, terror.Log(err) is called when we expect the error to be nil and get rid of the annoying golint check. Sometimes the error is not nil as expected, so it"s better to print the stack to find why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but we only can get stack when calling terror.Log from this pr.
we also need errors.Trace(err)
to know where throws the error
That"s enough for us to modify the code (identify the incorrect |
Codecov Report
@@ Coverage Diff @@
## master #803 +/- ##
==========================================
+ Coverage 78.22% 78.23% +0.01%
==========================================
Files 40 40
Lines 14700 14700
==========================================
+ Hits 11499 11501 +2
+ Misses 2520 2519 -1
+ Partials 681 680 -1 |
terror/terror.go
Outdated
var buf [4096]byte | ||
sz := runtime.Stack(buf[:], false) | ||
log.Error("encountered error", zap.Error(err), zap.String("stack", string(buf[:sz]))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps easier to just do
var buf [4096]byte | |
sz := runtime.Stack(buf[:], false) | |
log.Error("encountered error", zap.Error(err), zap.String("stack", string(buf[:sz]))) | |
log.Error("encountered error", zap.Error(errors.Trace(err))) |
or do we really need the exact stack where Log
is called 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need it!
We need the call stack to identify the misuse of terror.Log()
. @kennytm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tiancaiamao Ah ok. In that case errors.Trace
isn"t suitable since it won"t replace the error"s stack if it already exists. We should use errors.WithStack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* terror: print the stack in terror.Log() In TiDB, terror.Log(err) is called when we expect the error to be nil and get rid of the annoying golint check. Sometimes the error is not nil as expected, so it"s better to print the stack to find why * go fmt * address comment * address comment
In TiDB,
terror.Log(err)
is called when we expect the error to be nil and get rid of the annoying golint check.Sometimes the error is not nil as expected, so it"s better to print the stack to find why.
PTAL @lysu @kennytm