Passed
Push — master ( dd2fc4...1c253b )
by Nikita
02:08
created

decode.*FailedToReadSizeError.Error   A

Complexity

Conditions 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 8
dl 0
loc 12
ccs 0
cts 7
cp 0
crap 6
rs 10
c 0
b 0
f 0
nop 0
1
package decode
2
3
import (
4
	"errors"
5
	"reflect"
6
	"strings"
7
)
8
9
var (
10
	ErrUnknownType        = errors.New("unknown storage type")
11
	ErrCantSetValue       = errors.New("can't set value")
12
	ErrItemNotFound       = errors.New("item not found")
13
	ErrInvalidItem        = errors.New("invalid item")
14
	ErrInvalidStructValue = errors.New("invalid struct value")
15
)
16
17
type FailedToReadTypeError struct {
18
	Previous error
19
}
20
21
func (err *FailedToReadTypeError) Error() string {
22
	text := strings.Builder{}
23
	text.WriteString("failed to read type")
24
25
	if err.Previous == nil {
26
		return text.String()
27
	}
28
29
	text.WriteString(": ")
30
	text.WriteString(err.Previous.Error())
31
32
	return text.String()
33
}
34
35
func (err *FailedToReadTypeError) Unwrap() error {
36
	return err.Previous
37
}
38
39
type FailedToReadSizeError struct {
40
	Previous error
41
}
42
43
func (err *FailedToReadSizeError) Error() string {
44
	text := strings.Builder{}
45
	text.WriteString("failed to read size")
46
47
	if err.Previous == nil {
48
		return text.String()
49
	}
50
51
	text.WriteString(": ")
52
	text.WriteString(err.Previous.Error())
53
54
	return text.String()
55
}
56
57
func (err *FailedToReadSizeError) Unwrap() error {
58
	return err.Previous
59
}
60
61
type InvalidUnmarshalError struct {
62
	Type reflect.Type
63
}
64
65
func (e *InvalidUnmarshalError) Error() string {
66
	if e.Type == nil {
67
		return "binn: Unmarshal(nil)"
68
	}
69
70
	if e.Type.Kind() != reflect.Ptr {
71
		return "binn: Unmarshal(non-pointer " + e.Type.String() + ")"
72
	}
73
	return "binn: Unmarshal(nil " + e.Type.String() + ")"
74
}
75
76
type UnknownValueError struct {
77
	Expected reflect.Kind
78
	Got      reflect.Kind
79
}
80
81
func (e *UnknownValueError) Error() string {
82
	return "binn: Unknown value. Expected " + e.Expected.String() + ", got " + e.Got.String()
83
}
84