Skip to content

Commit

Permalink
Add Unwrap() method to standard error types
Browse files Browse the repository at this point in the history
Address #70
  • Loading branch information
viciious committed Dec 12, 2023
1 parent f3081f5 commit 51055c9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (e *ConnectionError) Timeout() bool {
return false
}

func (e *ConnectionError) Unwrap() error {
return e.error
}

// ContextError is returned when request has been ended with context timeout or cancel.
type ContextError struct {
error
Expand All @@ -88,6 +92,10 @@ func (e *ContextError) Timeout() bool {
return e.CtxErr == context.DeadlineExceeded
}

func (e *ContextError) Unwrap() error {
return e.CtxErr
}

// QueryError is returned when query error has been happened.
// It has error Code.
type QueryError struct {
Expand All @@ -113,6 +121,10 @@ func (e *QueryError) Timeout() bool {
return false
}

func (e *QueryError) Unwrap() error {
return e.error
}

// UnexpectedReplicaSetUUIDError is returned when ReplicaSetUUID set in Options.ReplicaSetUUID is not equal to ReplicaSetUUID
// received during Join or JoinWithSnap. It is only an AnonSlave error!
type UnexpectedReplicaSetUUIDError struct {
Expand All @@ -136,6 +148,10 @@ func (e *UnexpectedReplicaSetUUIDError) Is(target error) bool {
return ok
}

func (e *UnexpectedReplicaSetUUIDError) Unwrap() error {
return e.QueryError
}

var _ Error = (*ConnectionError)(nil)
var _ Error = (*QueryError)(nil)
var _ Error = (*ContextError)(nil)
Expand Down

0 comments on commit 51055c9

Please sign in to comment.