Skip to content

Commit fc849e5

Browse files
committed
godoc
1 parent 553e5d7 commit fc849e5

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

error_113.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ package errorx
44

55
import "reflect"
66

7-
// todo godoc
8-
// NB: Call to errors.As() converts any type of errorx error to any other type, therefore such calls may break semantics.
9-
// Note than calls to errors.Is() do not suffer from the same issue.
10-
// todo add errorx.As() ?
11-
// todo make another type for passing into errors.As()?
7+
// todo add errorx.As()?
8+
// todo make another 'go error type' for passing into errors.As()?
129
// todo when fixed, add tests for wrap/decorate etc.
10+
// As checks if target is of the same type as current error and, if true, sets target to this error value.
11+
// NB: Call to errors.As() converts any type of errorx error to any other type,
12+
// therefore such calls are currently unsafe for errorx errors and will likely break semantics.
13+
// Note than calls to errors.Is() do not suffer from the same issue.
1314
func (e *Error) As(target interface{}) bool {
1415
targetError, ok := target.(*error)
1516
if !ok {
@@ -25,18 +26,17 @@ func (e *Error) As(target interface{}) bool {
2526
return true
2627
}
2728

28-
// todo godoc
29+
// Is returns true if and only if target is errorx error that passes errorx type check against current error.
30+
// This behaviour is exactly the same as that of IsOfType().
31+
// See also: errors.Is()
2932
func (e *Error) Is(target error) bool {
3033
typedTarget := Cast(target)
31-
if typedTarget == nil {
32-
return false
33-
}
34-
35-
return e.IsOfType(typedTarget.Type())
34+
return typedTarget != nil && IsOfType(e, typedTarget.Type())
3635
}
3736

38-
// todo godoc
39-
// If e.Unwrap() returns a non-nil error w, then we say that e wraps w.
37+
// From errors package: if e.Unwrap() returns a non-nil error w, then we say that e wraps w.
38+
// Unwrap returns cause of current error in case it is wrapped transparently, nil otherwise.
39+
// See also: errors.Unwrap()
4040
func (e *Error) Unwrap() error {
4141
if e.cause != nil && e.transparent {
4242
return e.cause

0 commit comments

Comments
 (0)