This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 699
feat ExistStack: Add a public method to determine if the error has been appended to the stack. #239
Closed
Closed
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8aa1409
feat:
wbflooksky b3e14fa
feat func ExistStack(err error) bool:
wbflooksky 5969e20
fix: error method
wbflooksky 88c8636
feat: test ExistStack
wbflooksky 0247cb8
fix: error variable name
wbflooksky 5c191f9
style: optimizing code structure
wbflooksky 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 |
---|---|---|
|
@@ -106,6 +106,24 @@ func New(message string) error { | |
} | ||
} | ||
|
||
// ExistStack return an error already with stack | ||
// ExistStack will check all parent error | ||
func ExistStack(err error) bool { | ||
type stackTracer interface { | ||
StackTrace() StackTrace | ||
} | ||
if _, ok := err.(stackTracer); ok { | ||
return true | ||
} | ||
type causer interface { | ||
Cause() error | ||
} | ||
if value, ok := err.(causer); ok { | ||
return ExistStack(err.Cause()) | ||
} else { | ||
return false | ||
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. Every code path in the preceding Considering using:
Please check the implementation of 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. Thank you very much for your help |
||
} | ||
} | ||
// Errorf formats according to a format specifier and returns the string | ||
// as a value that satisfies error. | ||
// Errorf also records the stack trace at the point it was called. | ||
|
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.
Just checking
Cause() error
ignores the possibility of anUnwrap() error
which is kind of the preferred way of unwrapping errors now. So, this would only work with errors from this package, and those designed specifically for pre-unwrap compatibility with this package, which is no longer a strong argument since go1.13.