This repository was archived by the owner on Dec 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 707
get first stack trace info. #195
Closed
Closed
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ad3bc5c
support get first stack trace info.
9755d01
fix test bug. change code style to match the repo
f1d8585
add more test case. try to make the comment more detail
727b4af
remove space between comments and function
917fc22
opt return logic
5513201
Merge branch 'master' into master
wangsai-silence File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,3 +280,40 @@ func Cause(err error) error { | |
} | ||
return err | ||
} | ||
|
||
// Stack returns the earliest/deepest StackTrace attached to any of | ||
// the errors in the chain of Causes. If the error does not implement | ||
// Cause, the original error will be returned. If the error is nil, | ||
// nil will be returned without further investigation. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docstrings should not have a space between them an the function. I don’t know for sure this would break godoc, but convention suggest we strictly enforce it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. I'd remove it. Thank you. |
||
func Stack(err error) StackTrace { | ||
type causer interface { | ||
Cause() error | ||
} | ||
|
||
type stackTracer interface { | ||
StackTrace() StackTrace | ||
} | ||
wangsai-silence marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var topStackInfo StackTrace | ||
|
||
for { | ||
stackErr, ok := err.(stackTracer) | ||
if ok { | ||
topStackInfo = stackErr.StackTrace() | ||
} | ||
|
||
causer, ok := err.(causer) | ||
if !ok { | ||
break | ||
} | ||
|
||
err = causer.Cause() | ||
} | ||
|
||
if topStackInfo != nil { | ||
return topStackInfo | ||
} | ||
|
||
return nil | ||
wangsai-silence marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think you mean "the stacktrace from the original error will be returned"?