-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
89 lines (72 loc) · 1.82 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package amphtml
import (
"bytes"
"fmt"
"github.com/favclip/ampassador/amppb"
"github.com/favclip/html2html"
)
var _ error = &Error{}
type AMPErrorType int
const (
AMPValidatorError AMPErrorType = iota + 1
AMPValidatorWarning
AMPRemoveAttr
AMPDeprecation
AMPCreationTag
AMPInsertinoTag
)
func (v AMPErrorType) String() string {
switch v {
case AMPValidatorError:
return "AMPValidatorError"
case AMPValidatorWarning:
return "AMPValidatorWarning"
case AMPRemoveAttr:
return "AMPRemoveAttr"
case AMPDeprecation:
return "AMPDeprecation"
case AMPCreationTag:
return "AMPCreationTag"
case AMPInsertinoTag:
return "AMPInsertinoTag"
}
return "unknown"
}
type AMPError struct {
Type AMPErrorType
token html2html.Token
validatorSourceSpec *amppb.TagSpec
cause interface{}
}
func (e *AMPError) Error() string {
switch e.Type {
case AMPValidatorError, AMPCreationTag, AMPInsertinoTag:
return fmt.Sprintf("err %s spec: %s", e.Type, e.validatorSourceSpec.GetSpecName())
case AMPValidatorWarning, AMPRemoveAttr, AMPDeprecation:
return fmt.Sprintf("warn %s spec: %s", e.Type, e.validatorSourceSpec.GetSpecName())
}
return "AMPError: undenifed"
}
type AMPErrors []*AMPError
func (e AMPErrors) Error() string {
errBuf := bytes.NewBufferString("")
warnBuf := bytes.NewBufferString("")
for _, ampErr := range e {
switch ampErr.Type {
case AMPValidatorError, AMPCreationTag, AMPInsertinoTag:
errBuf.WriteString(ampErr.Error())
case AMPValidatorWarning, AMPRemoveAttr, AMPDeprecation:
warnBuf.WriteString(ampErr.Error())
}
}
return "AMPErrors: \n" + errBuf.String() + warnBuf.String()
}
func (e AMPErrors) HasFatalError() bool {
for _, ampErr := range e {
switch ampErr.Type {
case AMPValidatorError, AMPCreationTag, AMPInsertinoTag:
return true
}
}
return false
}