-
-
Notifications
You must be signed in to change notification settings - Fork 352
/
error.go
193 lines (148 loc) · 4.45 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package rod
import (
"context"
"fmt"
"github.com/go-rod/rod/lib/proto"
"github.com/go-rod/rod/lib/utils"
)
// TryError error.
type TryError struct {
Value interface{}
Stack string
}
func (e *TryError) Error() string {
return fmt.Sprintf("error value: %#v\n%s", e.Value, e.Stack)
}
// Is interface.
func (e *TryError) Is(err error) bool { _, ok := err.(*TryError); return ok }
// Unwrap stdlib interface.
func (e *TryError) Unwrap() error {
if err, ok := e.Value.(error); ok {
return err
}
return fmt.Errorf("%v", e.Value)
}
// ExpectElementError error.
type ExpectElementError struct {
*proto.RuntimeRemoteObject
}
func (e *ExpectElementError) Error() string {
return fmt.Sprintf("expect js to return an element, but got: %s", utils.MustToJSON(e))
}
// Is interface.
func (e *ExpectElementError) Is(err error) bool { _, ok := err.(*ExpectElementError); return ok }
// ExpectElementsError error.
type ExpectElementsError struct {
*proto.RuntimeRemoteObject
}
func (e *ExpectElementsError) Error() string {
return fmt.Sprintf("expect js to return an array of elements, but got: %s", utils.MustToJSON(e))
}
// Is interface.
func (e *ExpectElementsError) Is(err error) bool { _, ok := err.(*ExpectElementsError); return ok }
// ElementNotFoundError error.
type ElementNotFoundError struct{}
func (e *ElementNotFoundError) Error() string {
return "cannot find element"
}
// NotFoundSleeper returns ErrElementNotFound on the first call.
func NotFoundSleeper() utils.Sleeper {
return func(context.Context) error {
return &ElementNotFoundError{}
}
}
// ObjectNotFoundError error.
type ObjectNotFoundError struct {
*proto.RuntimeRemoteObject
}
func (e *ObjectNotFoundError) Error() string {
return fmt.Sprintf("cannot find object: %s", utils.MustToJSON(e))
}
// Is interface.
func (e *ObjectNotFoundError) Is(err error) bool { _, ok := err.(*ObjectNotFoundError); return ok }
// EvalError error.
type EvalError struct {
*proto.RuntimeExceptionDetails
}
func (e *EvalError) Error() string {
exp := e.Exception
return fmt.Sprintf("eval js error: %s %s", exp.Description, exp.Value)
}
// Is interface.
func (e *EvalError) Is(err error) bool { _, ok := err.(*EvalError); return ok }
// NavigationError error.
type NavigationError struct {
Reason string
}
func (e *NavigationError) Error() string {
return "navigation failed: " + e.Reason
}
// Is interface.
func (e *NavigationError) Is(err error) bool { _, ok := err.(*NavigationError); return ok }
// PageCloseCanceledError error.
type PageCloseCanceledError struct{}
func (e *PageCloseCanceledError) Error() string {
return "page close canceled"
}
// NotInteractableError error. Check the doc of Element.Interactable for details.
type NotInteractableError struct{}
func (e *NotInteractableError) Error() string {
return "element is not cursor interactable"
}
// InvisibleShapeError error.
type InvisibleShapeError struct {
*Element
}
// Error ...
func (e *InvisibleShapeError) Error() string {
return fmt.Sprintf("element has no visible shape or outside the viewport: %s", e.String())
}
// Is interface.
func (e *InvisibleShapeError) Is(err error) bool { _, ok := err.(*InvisibleShapeError); return ok }
// Unwrap ...
func (e *InvisibleShapeError) Unwrap() error {
return &NotInteractableError{}
}
// CoveredError error.
type CoveredError struct {
*Element
}
// Error ...
func (e *CoveredError) Error() string {
return fmt.Sprintf("element covered by: %s", e.String())
}
// Unwrap ...
func (e *CoveredError) Unwrap() error {
return &NotInteractableError{}
}
// Is interface.
func (e *CoveredError) Is(err error) bool { _, ok := err.(*CoveredError); return ok }
// NoPointerEventsError error.
type NoPointerEventsError struct {
*Element
}
// Error ...
func (e *NoPointerEventsError) Error() string {
return fmt.Sprintf("element's pointer-events is none: %s", e.String())
}
// Unwrap ...
func (e *NoPointerEventsError) Unwrap() error {
return &NotInteractableError{}
}
// Is interface.
func (e *NoPointerEventsError) Is(err error) bool { _, ok := err.(*NoPointerEventsError); return ok }
// PageNotFoundError error.
type PageNotFoundError struct{}
func (e *PageNotFoundError) Error() string {
return "cannot find page"
}
// NoShadowRootError error.
type NoShadowRootError struct {
*Element
}
// Error ...
func (e *NoShadowRootError) Error() string {
return fmt.Sprintf("element has no shadow root: %s", e.String())
}
// Is interface.
func (e *NoShadowRootError) Is(err error) bool { _, ok := err.(*NoShadowRootError); return ok }