-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
69 lines (57 loc) · 1.3 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
package weeny
import (
"errors"
"fmt"
"go.uber.org/zap"
)
var PresetUnloggedErrors = []error{
ErrVisited,
ErrURLInvalid,
ErrNoElemFound,
ErrMaxDepth,
ErrForbiddenDomain,
ErrNotInteractable,
}
var (
// errors from bot
ErrNoElemFound = errors.New("no element found")
ErrNotInteractable = errors.New("elem not interactable")
)
var (
// errors of control logics
ErrForbiddenDomain = errors.New("forbidden domain")
ErrMaxDepth = errors.New("max depth limit reached")
ErrVisited = errors.New("url already visited")
ErrURLInvalid = errors.New("url invalid error")
)
func errVisited(msg string) error {
return fmt.Errorf("%w: %s", ErrVisited, msg)
}
func errURLInvalid(msg string) error {
return fmt.Errorf("%w: %s", ErrURLInvalid, msg)
}
// Echo warn if log happens
func (c *Crawler) Echo(err error) {
if err != nil {
c.logger.Warn("unhandled error", zap.Error(err))
}
}
// Pie print if error not in ignored errors
func (c *Crawler) Pie(err error) {
err = c.filterErrors(err)
if err != nil {
c.logger.Warn("unhandled error", zap.Error(err))
}
}
func (c *Crawler) filterErrors(err error) error {
errs := PresetUnloggedErrors
if len(c.ignoredErrors) != 0 {
errs = c.ignoredErrors
}
for _, e := range errs {
if errors.Is(err, e) {
return nil
}
}
return err
}