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

terror: print the stack in terror.Log() #803

Merged
merged 5 commits into from
Apr 11, 2020

Conversation

tiancaiamao
Copy link
Collaborator

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.

[2020/04/08 21:09:00.837 +08:00] [ERROR] [terror.go:363] ["encountered error"] [error="[ddl:1273]Unknown collation: "

PTAL @lysu @kennytm

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
@tiancaiamao tiancaiamao requested a review from a team April 9, 2020 12:39
Copy link
Collaborator

@lysu lysu left a 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

@tiancaiamao
Copy link
Collaborator Author

we can only get stack when calling terror.Log from this pr.

That"s enough for us to modify the code (identify the incorrect terror.Log call)

@codecov
Copy link

codecov bot commented Apr 9, 2020

Codecov Report

Merging #803 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            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
Comment on lines 364 to 366
var buf [4096]byte
sz := runtime.Stack(buf[:], false)
log.Error("encountered error", zap.Error(err), zap.String("stack", string(buf[:sz])))
Copy link
Contributor

@kennytm kennytm Apr 10, 2020

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

Suggested change
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 🤔

Copy link
Collaborator Author

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

Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@kennytm kennytm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kennytm kennytm added the status/LGT2 LGT2 label Apr 11, 2020
@kennytm kennytm merged commit 3383549 into pingcap:master Apr 11, 2020
tiancaiamao added a commit to tiancaiamao/parser that referenced this pull request Apr 27, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants