-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror.go
74 lines (58 loc) · 1.2 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
package chromy
import (
"fmt"
"strings"
"github.com/mafredri/cdp/rpcc"
)
var (
ErrNodeNotFound = fmt.Errorf("dom node not found")
ErrNoQueryFunc = fmt.Errorf("no query function")
ErrNoMatchFunc = fmt.Errorf("no match function")
ErrUnableToResolveNode = fmt.Errorf("unable to resolve node")
)
type causer interface {
Cause() error
}
func errCause(err error) error {
c, ok := err.(causer)
if !ok {
return err
}
return c.Cause()
}
func rpccResponseError(err error) (*rpcc.ResponseError, bool) {
respErr, ok := errCause(err).(*rpcc.ResponseError)
return respErr, ok
}
func nonblockErrorPush(ch chan error, err error) {
select {
case ch <- err:
default:
}
}
func actionErr(action string, err error) error {
if err == nil {
return nil
}
ae, ok := err.(*ActionError)
if ok {
ae.action = append(ae.action, "")
copy(ae.action[1:], ae.action)
ae.action[0] = action
return ae
}
return &ActionError{
action: []string{action},
err: err,
}
}
type ActionError struct {
action []string
err error
}
func (a *ActionError) Error() string {
return fmt.Sprintf("[%s] %s", strings.Join(a.action, "; "), a.err)
}
func (a *ActionError) Cause() error {
return a.err
}