-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
reader_exception.go
68 lines (55 loc) · 1.02 KB
/
reader_exception.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
package gozxing
import (
"fmt"
errors "golang.org/x/xerrors"
)
type ReaderException interface {
error
readerException()
}
type readerException struct {
exception
}
func WrapReaderException(e error) ReaderException {
return readerException{
wrapException("ReaderException", e),
}
}
func (readerException) readerException() {}
type exception struct {
msg string
next error
frame errors.Frame
}
func newException(prefix string, args ...interface{}) exception {
msg := prefix
if len(args) > 0 {
msg += ": " + fmt.Sprintf(args[0].(string), args[1:]...)
}
return exception{
msg,
nil,
errors.Caller(2),
}
}
func wrapException(msg string, next error) exception {
return exception{
msg,
next,
errors.Caller(2),
}
}
func (e exception) Error() string {
return e.msg
}
func (e exception) Unwrap() error {
return e.next
}
func (e exception) Format(s fmt.State, v rune) {
errors.FormatError(e, s, v)
}
func (e exception) FormatError(p errors.Printer) error {
p.Print(e.msg)
e.frame.Format(p)
return e.next
}