-
Notifications
You must be signed in to change notification settings - Fork 13
/
error.go
61 lines (46 loc) · 1.62 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
package regroup
import (
"fmt"
"reflect"
)
// CompileError returned on regex compilation error
type CompileError struct{ err error }
func (c *CompileError) Error() string {
return fmt.Sprintf("compilation error: %v", c.err)
}
// NoMatchFoundError indicates no regex matches for given string
type NoMatchFoundError struct{}
func (n *NoMatchFoundError) Error() string {
return "no match found for given string"
}
// NotStructPtrError returned when given target is not a truct pointer
type NotStructPtrError struct{}
func (n *NotStructPtrError) Error() string {
return "expected struct pointer"
}
// UnknownGroupError returned when given regex group tag isn't exists in compiled regex groups
type UnknownGroupError struct{ group string }
func (u *UnknownGroupError) Error() string {
return fmt.Sprintf("group \"%s\" haven't found in regex", u.group)
}
// TypeNotParsableError returned when the type of struct field is not parsable
type TypeNotParsableError struct{ typ reflect.Type }
func (t *TypeNotParsableError) Error() string {
return fmt.Sprintf("type \"%v\" is not parsable", t.typ)
}
// ParseError returned when the conversion to target struct field type has failed
type ParseError struct {
group string
err error
}
func (p *ParseError) Error() string {
return fmt.Sprintf("error parsing group \"%s\": %v", p.group, p.err)
}
// RequiredGroupIsEmpty returned when a required group is empty in the re match
type RequiredGroupIsEmpty struct {
groupName string
fieldName string
}
func (r *RequiredGroupIsEmpty) Error() string {
return fmt.Sprintf("required regroup \"%s\" is empty for field \"%s\"", r.groupName, r.fieldName)
}