-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
54 lines (43 loc) · 1.24 KB
/
errors.go
File metadata and controls
54 lines (43 loc) · 1.24 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
52
53
54
package bencoding
import (
"fmt"
"reflect"
)
var (
ErrMinusZeroInteger = fmt.Errorf("-0 is not a valid integer")
)
type ErrDataCastFail struct {
castedData interface{}
data interface{}
}
func NewErrCastFail(data interface{}, castedData interface{}) ErrDataCastFail {
return ErrDataCastFail{
castedData: castedData,
data: data,
}
}
func (err ErrDataCastFail) Error() string {
return fmt.Sprintf("failed to cast data to %v, data is of type %v", reflect.TypeOf(err.castedData), reflect.TypeOf(err.data))
}
type ErrLeadingZeroInteger struct {
invalidInt string
}
func NewErrLeadingZeroInteger(invalidInt string) ErrLeadingZeroInteger {
return ErrLeadingZeroInteger{
invalidInt: invalidInt,
}
}
func (err ErrLeadingZeroInteger) Error() string {
return fmt.Sprintf("%s is not a valid integer value, leading 0 are not allowed", err.invalidInt)
}
type ErrInvalidType struct {
invalidType reflect.Type
}
func NewErrInvalidType(invalidType interface{}) ErrInvalidType {
return ErrInvalidType{
invalidType: reflect.TypeOf(invalidType),
}
}
func (err ErrInvalidType) Error() string {
return fmt.Sprintf("value of type %v cannot be encoded, only int, string, []interface{} and map[string]interface{} can be encoded", err.invalidType)
}