-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
78 lines (57 loc) · 1.71 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
package htmlcheck
import (
"errors"
"fmt"
)
type ValidationErrorList []error
func (el ValidationErrorList) Join() error {
var err error
for _, e := range el {
err = errors.Join(err, e)
}
return err
}
type ValidationError interface {
Error() string
Details() ErrorDetails
}
type ErrorDetails struct {
TagName string
AttributeName string
AttributeValue string
Reason ErrorReason
}
func (d ErrorDetails) Details() ErrorDetails {
return d
}
type ErrInvAttribute struct{ ErrorDetails }
func (e ErrInvAttribute) Error() string {
return fmt.Sprintf("invalid attribute '%s' in tag '%s'", e.AttributeName, e.TagName)
}
type ErrInvClosedBeforeOpened struct{ ErrorDetails }
func (e ErrInvClosedBeforeOpened) Error() string {
return fmt.Sprintf("tag '%s' closed before opened", e.TagName)
}
type ErrInvDuplicatedAttribute struct{ ErrorDetails }
func (e ErrInvDuplicatedAttribute) Error() string {
return fmt.Sprintf("duplicate attribute '%s' in tag '%s'", e.AttributeName, e.TagName)
}
type ErrInvTag struct{ ErrorDetails }
func (e ErrInvTag) Error() string {
return fmt.Sprintf("invalid tag '%s'", e.TagName)
}
type ErrInvNotProperlyClosed struct{ ErrorDetails }
func (e ErrInvNotProperlyClosed) Error() string {
return fmt.Sprintf("tag '%s' is never closed", e.TagName)
}
type ErrInvAttributeValue struct{ ErrorDetails }
func (e ErrInvAttributeValue) Error() string {
return fmt.Sprintf("invalid attribute value '%s' in attribute '%s' in tag '%s'", e.AttributeValue, e.AttributeName, e.TagName)
}
type ErrInvEOF struct{ ErrorDetails }
func (e ErrInvEOF) Error() string {
return fmt.Sprintln("error occurred during tokenization")
}
func isEOF(err error) bool {
return errors.As(err, &ErrInvEOF{})
}