-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
83 lines (71 loc) · 1.59 KB
/
errors.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package gonfc
import (
"errors"
"fmt"
"os"
)
var (
NFC_EIO error = &nfcIOError{}
NFC_EINVARG error = errors.New("NFC_EINVARG")
NFC_EDEVNOTSUPP error = errors.New("NFC_EDEVNOTSUPP")
NFC_ENOTSUCHDEV error = errors.New("NFC_ENOTSUCHDEV")
NFC_EOVFLOW error = errors.New("NFC_EOVFLOW")
NFC_ETIMEOUT error = &nfcTimeoutError{}
NFC_EOPABORTED error = errors.New("NFC_EOPABORTED")
NFC_ENOTIMPL error = errors.New("NFC_ENOTIMPL")
NFC_ETGRELEASED error = errors.New("NFC_ETGRELEASED")
NFC_ERFTRANS error = errors.New("NFC_ERFTRANS")
NFC_EMFCAUTHFAIL error = errors.New("NFC_EMFCAUTHFAIL")
NFC_ESOFT error = errors.New("NFC_ESOFT")
NFC_ECHIP error = errors.New("NFC_ECHIP")
)
type nfcTimeoutError struct{}
func (nfcTimeoutError) Error() string {
return "NFC_ETIMEOUT"
}
func (nfcTimeoutError) Timeout() bool {
// compatibility with os.IsTimeout(err)
return true
}
type nfcIOError struct {
w error
m string
}
func (e *nfcIOError) Error() string {
return e.m
}
func (e *nfcIOError) Is(err error) bool {
_, ok := err.(*nfcIOError)
return err != nil && ok
}
func (e *nfcIOError) Unwrap() error {
return e.w
}
func BuildNFC_EIO(err error) error {
var m string
if err == nil {
m = "NFC_EIO"
} else {
m = fmt.Sprintf("NFC_EIO: %s", err.Error())
}
return &nfcIOError{
w: err,
m: m,
}
}
type timeout interface {
Timeout() bool
}
func IsTimeout(err error) bool {
if err == nil {
return false
}
if os.IsTimeout(err) {
return true
}
if to, ok := err.(timeout); ok {
return to.Timeout()
}
w := errors.Unwrap(err)
return IsTimeout(w)
}