This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
74 lines (62 loc) · 1.65 KB
/
error.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
package blood_contracts_go
import (
"fmt"
"reflect"
)
type MismatchTypeError struct {
Expected []reflect.Kind
Got reflect.Kind
}
func (e *MismatchTypeError) Error() string {
return fmt.Sprintf("Mismatch type. Expected: %v; Got: %v", e.Expected, e.Got)
}
func NewMismatchTypeError(expected []reflect.Kind, got reflect.Kind) *MismatchTypeError {
return &MismatchTypeError{
Expected: expected,
Got: got,
}
}
func NewMismatchTypeErrorFromInterface(expected []reflect.Kind, got interface{}) *MismatchTypeError {
return NewMismatchTypeError(expected, reflect.TypeOf(got).Kind())
}
type ComparerType uint
const (
EqualComparer ComparerType = iota
LessOrEqualComparer
LessComparer
BiggerComparer
BiggerOrEqualComparer
)
type NumberCompareError struct {
Container Container
Comparer ComparerType
CompareResult CompareResult
CompareWith Container
}
func operationFromComparerType(comparer ComparerType) string {
switch comparer {
case EqualComparer:
return "=="
case LessOrEqualComparer:
return "<="
case LessComparer:
return "<"
case BiggerComparer:
return "<"
case BiggerOrEqualComparer:
return ">"
}
panic("unknown comparer type")
}
func (e *NumberCompareError) Error() string {
return fmt.Sprintf("Number comparing error. Expected %f %v %f", e.Container.Value(),
operationFromComparerType(e.Comparer), e.CompareWith.Value())
}
func NewNumberCompareError(container Container, comparer ComparerType, compareResult CompareResult, compareWith Container) *NumberCompareError {
return &NumberCompareError{
Container: container,
Comparer: comparer,
CompareResult: compareResult,
CompareWith: compareWith,
}
}