-
-
Notifications
You must be signed in to change notification settings - Fork 328
/
error.go
147 lines (114 loc) · 2.95 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package rod
import (
"fmt"
"reflect"
"github.com/go-rod/rod/lib/proto"
"github.com/go-rod/rod/lib/utils"
)
// ErrTry error
type ErrTry struct {
Value interface{}
}
func (e *ErrTry) Error() string {
return fmt.Sprintf("error value: %#v", e.Value)
}
// Is interface
func (e *ErrTry) Is(err error) bool {
return reflect.TypeOf(e) == reflect.TypeOf(err)
}
// ErrExpectElement error
type ErrExpectElement struct {
*proto.RuntimeRemoteObject
}
func (e *ErrExpectElement) Error() string {
return fmt.Sprintf("expect js to return an element, but got: %s", utils.MustToJSON(e))
}
// Is interface
func (e *ErrExpectElement) Is(err error) bool {
return reflect.TypeOf(e) == reflect.TypeOf(err)
}
// ErrExpectElements error
type ErrExpectElements struct {
*proto.RuntimeRemoteObject
}
func (e *ErrExpectElements) Error() string {
return fmt.Sprintf("expect js to return an array of elements, but got: %s", utils.MustToJSON(e))
}
// Is interface
func (e *ErrExpectElements) Is(err error) bool {
return reflect.TypeOf(e) == reflect.TypeOf(err)
}
// ErrElementNotFound error
type ErrElementNotFound struct {
}
func (e *ErrElementNotFound) Error() string {
return "cannot find element"
}
// ErrObjectNotFound error
type ErrObjectNotFound struct {
*proto.RuntimeRemoteObject
}
func (e *ErrObjectNotFound) Error() string {
return fmt.Sprintf("cannot find object: %s", utils.MustToJSON(e))
}
// Is interface
func (e *ErrObjectNotFound) Is(err error) bool {
return reflect.TypeOf(e) == reflect.TypeOf(err)
}
// ErrEval error
type ErrEval struct {
*proto.RuntimeExceptionDetails
}
func (e *ErrEval) Error() string {
exp := e.Exception
return fmt.Sprintf("eval js error: %s %s", exp.Description, exp.Value)
}
// Is interface
func (e *ErrEval) Is(err error) bool {
return reflect.TypeOf(e) == reflect.TypeOf(err)
}
// ErrNavigation error
type ErrNavigation struct {
Reason string
}
func (e *ErrNavigation) Error() string {
return "navigation failed: " + e.Reason
}
// Is interface
func (e *ErrNavigation) Is(err error) bool {
return reflect.TypeOf(e) == reflect.TypeOf(err)
}
// ErrPageCloseCanceled error
type ErrPageCloseCanceled struct {
}
func (e *ErrPageCloseCanceled) Error() string {
return "page close canceled"
}
// ErrNotInteractable error. Check the doc of Element.Interactable for details.
type ErrNotInteractable struct{}
func (e *ErrNotInteractable) Error() string {
return "element is not cursor interactable"
}
// ErrInvisibleShape error.
type ErrInvisibleShape struct {
}
func (e *ErrInvisibleShape) Error() string {
return "element has no visible shape"
}
func (e *ErrInvisibleShape) Unwrap() error {
return &ErrNotInteractable{}
}
// ErrCovered error.
type ErrCovered struct {
*Element
}
func (e *ErrCovered) Error() string {
return fmt.Sprintf("element covered by: %v", e.MustHTML())
}
func (e *ErrCovered) Unwrap() error {
return &ErrNotInteractable{}
}
// Is interface
func (e *ErrCovered) Is(err error) bool {
return reflect.TypeOf(e) == reflect.TypeOf(err)
}