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 715
feat: support std errors functions #213
Merged
+203
−3
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
69e8329
feat: support std errors functions
Sherlock-Holo 5526281
style: delete useless comments
Sherlock-Holo 227a7b4
build: update makefile
Sherlock-Holo 9c503b9
build: fix makefile
Sherlock-Holo 34b42fb
chore: delete useless comments
Sherlock-Holo 057b7e2
Restore Makefile
Sherlock-Holo d9389f6
revert: revert some change
Sherlock-Holo c93d5ce
Merge remote-tracking branch 'pkg/master' into support-std-errors
Sherlock-Holo d0d34df
test: add more check for As unit test
Sherlock-Holo 487ff7b
revert: only support Is As Unwrap for >=go1.13
Sherlock-Holo e473c5d
feat(Unwrap): allow <go1.13 can use Unwrap
Sherlock-Holo bd678d4
test: add go1.13 errors compatibility check
Sherlock-Holo 613b81c
refactor(Unwrap): don't allow <go1.13 use Unwrap
Sherlock-Holo 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // +build go1.13 | ||
|
|
||
| package errors | ||
|
|
||
| import ( | ||
| stderrors "errors" | ||
| ) | ||
|
|
||
| // Is reports whether any error in err's chain matches target. | ||
| // | ||
| // The chain consists of err itself followed by the sequence of errors obtained by | ||
| // repeatedly calling Unwrap. | ||
| // | ||
| // An error is considered to match a target if it is equal to that target or if | ||
| // it implements a method Is(error) bool such that Is(target) returns true. | ||
| func Is(err, target error) bool { return stderrors.Is(err, target) } | ||
|
|
||
| // As finds the first error in err's chain that matches target, and if so, sets | ||
| // target to that error value and returns true. | ||
| // | ||
| // The chain consists of err itself followed by the sequence of errors obtained by | ||
| // repeatedly calling Unwrap. | ||
| // | ||
| // An error matches target if the error's concrete value is assignable to the value | ||
| // pointed to by target, or if the error has a method As(interface{}) bool such that | ||
| // As(target) returns true. In the latter case, the As method is responsible for | ||
| // setting target. | ||
| // | ||
| // As will panic if target is not a non-nil pointer to either a type that implements | ||
| // error, or to any interface type. As returns false if err is nil. | ||
| func As(err error, target interface{}) bool { return stderrors.As(err, target) } | ||
|
|
||
| // Unwrap returns the result of calling the Unwrap method on err, if err's | ||
| // type contains an Unwrap method returning error. | ||
| // Otherwise, Unwrap returns nil. | ||
| func Unwrap(err error) error { | ||
| return stderrors.Unwrap(err) | ||
| } |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.