-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
51 lines (43 loc) · 1.25 KB
/
Copy patherror.go
File metadata and controls
51 lines (43 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2019 Hervé Gouchet. All rights reserved.
// Use of this source code is governed by the MIT License
// that can be found in the LICENSE file.
package backoff
const (
errPrefix = "backoff: "
errRetryMsg = "maximum execution number exhausted"
errDeadlineMsg = "context deadline exceeded"
)
// Common errors.
var (
// ErrRetry is returns when the maximum execution number is exhausted.
ErrRetry = &Error{Reason: errRetryMsg}
// ErrDeadlineExceeded is the error returned when the context's deadline passes.
ErrDeadlineExceeded = &Error{Reason: errDeadlineMsg}
)
// Error represents an error.
type Error struct {
Reason string
Err error
}
// DeadlineExceeded reports whether this error represents a deadline exceeded.
func (e Error) DeadlineExceeded() bool {
return e.Reason == errDeadlineMsg
}
// Error implements the error interface.
func (e Error) Error() string {
if e.Err != nil {
return errPrefix + e.Reason + ": " + e.Err.Error()
}
return errPrefix + e.Reason
}
// Unwrap returns the embedded error.
func (e Error) Unwrap(err error) error {
return e.Err
}
// newErrRetry embeds the error in a retrying error.
func newErrRetry(err error) error {
if err != nil {
return &Error{Reason: errRetryMsg, Err: err}
}
return ErrRetry
}