forked from ttacon/uri
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
98 lines (88 loc) · 2.35 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package uri
type (
// Error from the github.com/fredbi/uri module.
Error interface {
error
}
)
// Generic validation errors.
var (
ErrInvalidURI = Error(newErr("not a valid URI"))
ErrInvalidCharacter = Error(newErr("invalid character in URI"))
ErrInvalidEscaping = Error(newErr("invalid percent-escaping sequence"))
)
// URI-specific errors
var (
ErrNoSchemeFound = Error(newErr("no scheme found in URI"))
ErrInvalidScheme = Error(newErr("invalid scheme in URI"))
ErrInvalidQuery = Error(newErr("invalid query string in URI"))
ErrInvalidFragment = Error(newErr("invalid fragment in URI"))
)
// Authority-specific errors
var (
ErrInvalidPath = Error(newErr("invalid path in URI"))
ErrInvalidHost = Error(newErr("invalid host in URI"))
ErrInvalidPort = Error(newErr("invalid port in URI"))
ErrInvalidUserInfo = Error(newErr("invalid userinfo in URI"))
ErrMissingHost = Error(newErr("missing host in URI"))
ErrInvalidHostAddress = Error(newErr("invalid address for host"))
ErrInvalidRegisteredName = Error(newErr("invalid host (registered name)"))
ErrInvalidDNSName = Error(newErr("invalid host (DNS name)"))
)
/*
// tells when a validation error originates from the authority part.
func isAuthorityErr(err error) bool {
switch err {
case ErrInvalidPath:
return true
case ErrInvalidHost:
return true
case ErrInvalidPort:
return true
case ErrMissingHost:
return true
case ErrInvalidHostAddress:
return true
case ErrInvalidRegisteredName:
return true
case ErrInvalidDNSName:
return true
default:
log.Printf("error Is with: %q", spew.Sdump(err))
return false
}
}
*/
type ipError uint8
const (
errInvalidCharacter ipError = iota
errValueGreater255
errAtLeastOneDigit
errLeadingZero
errTooLong
errTooShort
)
func (e ipError) Error() string {
switch e {
case errInvalidCharacter:
return "invalid character in IPv4 literal"
case errValueGreater255:
return "invalid IPv4 octet: IP field has value > 255"
case errAtLeastOneDigit:
return "IPv4 field must have at least one digit"
case errLeadingZero:
return "IPv4 field has octet with leading zero"
case errTooLong:
return "IPv4 address too long"
case errTooShort:
return "IPv4 address too short"
default:
return ""
}
}
func (u uri) Err() error {
return u.err
}
func (a authorityInfo) Err() error {
return a.err
}