19
19
20
20
import com.google.common.collect.ImmutableSet;
21
21
import com.google.common.collect.Iterables;
22
+
22
23
import org.openqa.selenium.ElementClickInterceptedException;
23
24
import org.openqa.selenium.ElementNotInteractableException;
24
-
import org.openqa.selenium.ImeActivationFailedException;
25
-
import org.openqa.selenium.ImeNotAvailableException;
26
25
import org.openqa.selenium.InvalidArgumentException;
27
26
import org.openqa.selenium.InvalidCookieDomainException;
28
27
import org.openqa.selenium.InvalidElementStateException;
@@ -101,6 +100,70 @@ public class ErrorCodes {
101
100
public static final int METHOD_NOT_ALLOWED = 405;
102
101
103
102
private static final Logger log = Logger.getLogger(ErrorCodes.class.getName());
103
+
// Every row on this table should be self-explanatory, except for the two booleans at the end.
104
+
// The first of these is "isCanonicalJsonCodeForException". This means that when doing the mapping
105
+
// for a JSON Wire Protocol status code, this KnownError provides the exception that should be
106
+
// thrown. The second boolean is "isCanonicalForW3C". This means that when mapping a state or
107
+
// exception to a W3C state, this KnownError provides the default exception and Json Wire Protocol
108
+
// status to send.
109
+
private static final ImmutableSet<KnownError> KNOWN_ERRORS = ImmutableSet.<KnownError>builder()
110
+
.add(new KnownError(ASYNC_SCRIPT_TIMEOUT, "script timeout", 500, ScriptTimeoutException.class, true, true))
111
+
.add(new KnownError(ELEMENT_CLICK_INTERCEPTED, "element click intercepted", 400, ElementClickInterceptedException.class, true, true))
112
+
.add(new KnownError(ELEMENT_NOT_INTERACTABLE, "element not interactable", 400, ElementNotInteractableException.class, true, true))
113
+
.add(new KnownError(INVALID_ARGUMENT, "invalid argument", 400, InvalidArgumentException.class, true, true))
114
+
.add(new KnownError(INVALID_COOKIE_DOMAIN, "invalid cookie domain", 400, InvalidCookieDomainException.class, true, true))
115
+
.add(new KnownError(INVALID_ELEMENT_STATE, "invalid element state", 400, InvalidElementStateException.class, true, true))
116
+
.add(new KnownError(INVALID_SELECTOR_ERROR, "invalid selector", 400, InvalidSelectorException.class, true, true))
117
+
.add(new KnownError(INVALID_XPATH_SELECTOR, "invalid selector", 400, InvalidSelectorException.class, false, false))
118
+
.add(new KnownError(INVALID_XPATH_SELECTOR_RETURN_TYPER, "invalid selector", 400, InvalidSelectorException.class, false, true))
119
+
.add(new KnownError(JAVASCRIPT_ERROR, "javascript error", 500, JavascriptException.class, true, true))
120
+
.add(new KnownError(METHOD_NOT_ALLOWED, "unknown method", 405, UnsupportedCommandException.class, false, true))
121
+
.add(new KnownError(METHOD_NOT_ALLOWED, "unsupported operation", 500, UnsupportedCommandException.class, false, true))
122
+
.add(new KnownError(MOVE_TARGET_OUT_OF_BOUNDS, "move target out of bounds", 500, MoveTargetOutOfBoundsException.class, true, true))
123
+
.add(new KnownError(NO_ALERT_PRESENT, "no such alert", 404, NoAlertPresentException.class, true, true))
124
+
.add(new KnownError(NO_SUCH_COOKIE, "no such cookie", 404, NoSuchCookieException.class, true, true))
125
+
.add(new KnownError(NO_SUCH_ELEMENT, "no such element", 404, NoSuchElementException.class, true, true))
126
+
.add(new KnownError(NO_SUCH_FRAME, "no such frame", 404, NoSuchFrameException.class, true, true))
127
+
.add(new KnownError(NO_SUCH_SESSION, "invalid session id", 404, NoSuchSessionException.class, true, true))
128
+
.add(new KnownError(NO_SUCH_SHADOW_ROOT, "no such shadow root", 404, NoSuchShadowRootException.class, true, true))
129
+
.add(new KnownError(NO_SUCH_WINDOW, "no such window", 404, NoSuchWindowException.class, true, true))
130
+
.add(new KnownError(SESSION_NOT_CREATED, "session not created", 500, SessionNotCreatedException.class ,true, true))
131
+
.add(new KnownError(STALE_ELEMENT_REFERENCE, "stale element reference", 404, StaleElementReferenceException.class, true, true))
132
+
.add(new KnownError(TIMEOUT, "timeout", 500, TimeoutException.class, true, true))
133
+
.add(new KnownError(XPATH_LOOKUP_ERROR, "invalid selector", 400, InvalidSelectorException.class, false, false))
134
+
.add(new KnownError(UNABLE_TO_CAPTURE_SCREEN, "unable to capture screen", 500, ScreenshotException.class, true, true))
135
+
.add(new KnownError(UNABLE_TO_SET_COOKIE, "unable to set cookie", 500, UnableToSetCookieException.class, true, true))
136
+
.add(new KnownError(UNEXPECTED_ALERT_PRESENT, "unexpected alert open", 500, UnhandledAlertException.class, true, true))
137
+
.add(new KnownError(UNHANDLED_ERROR, "unknown error", 500, WebDriverException.class, true, true))
138
+
.add(new KnownError(UNKNOWN_COMMAND, "unknown command", 404, UnsupportedCommandException.class, true, true))
139
+
140
+
.build();
141
+
142
+
static {{
143
+
// Validate uniqueness constraints.
144
+
//
145
+
// There should be only one canonical JSON Wire protocol code per exception
146
+
Map<Object, Set<KnownError>> matched = new HashMap<>();
147
+
for (KnownError knownError : KNOWN_ERRORS) {
148
+
matched.computeIfAbsent(knownError, key -> new HashSet<>()).add(knownError);
149
+
}
150
+
for (Set<KnownError> errors : matched.values()) {
151
+
if (errors.size() != 1) {
152
+
throw new RuntimeException("Duplicate canonical exceptions: " + errors);
153
+
}
154
+
}
155
+
156
+
// There should only be one canonical W3C code to JSON Wire Protocol code
157
+
// matched = new HashMap<>();
158
+
// for (KnownError error : KNOWN_ERRORS) {
159
+
// matched.computeIfAbsent(error.getW3cCode(), key -> new HashSet<>()).add(error);
160
+
// }
161
+
// for (Set<KnownError> errors : matched.values()) {
162
+
// if (errors.size() != 1) {
163
+
// throw new RuntimeException("Duplicate canonical w3c state codes: " + errors);
164
+
// }
165
+
// }
166
+
}}
104
167
105
168
public String toState(Integer status) {
106
169
if (status == null) {
@@ -211,73 +274,6 @@ public boolean isMappableError(Throwable rootCause) {
211
274
return !possibleMatches.isEmpty();
212
275
}
213
276
214
-
// Every row on this table should be self-explanatory, except for the two booleans at the end.
215
-
// The first of these is "isCanonicalJsonCodeForException". This means that when doing the mapping
216
-
// for a JSON Wire Protocol status code, this KnownError provides the exception that should be
217
-
// thrown. The second boolean is "isCanonicalForW3C". This means that when mapping a state or
218
-
// exception to a W3C state, this KnownError provides the default exception and Json Wire Protocol
219
-
// status to send.
220
-
private static final ImmutableSet<KnownError> KNOWN_ERRORS = ImmutableSet.<KnownError>builder()
221
-
.add(new KnownError(ASYNC_SCRIPT_TIMEOUT, "script timeout", 500, ScriptTimeoutException.class, true, true))
222
-
.add(new KnownError(ELEMENT_CLICK_INTERCEPTED, "element click intercepted", 400, ElementClickInterceptedException.class, true, true))
223
-
.add(new KnownError(ELEMENT_NOT_INTERACTABLE, "element not interactable", 400, ElementNotInteractableException.class, true, true))
224
-
.add(new KnownError(IME_ENGINE_ACTIVATION_FAILED, "unsupported operation", 500, ImeActivationFailedException.class, true, false))
225
-
.add(new KnownError(IME_NOT_AVAILABLE, "unsupported operation", 500, ImeNotAvailableException.class, true, false))
226
-
.add(new KnownError(INVALID_ARGUMENT, "invalid argument", 400, InvalidArgumentException.class, true, true))
227
-
.add(new KnownError(INVALID_COOKIE_DOMAIN, "invalid cookie domain", 400, InvalidCookieDomainException.class, true, true))
228
-
.add(new KnownError(INVALID_ELEMENT_STATE, "invalid element state", 400, InvalidElementStateException.class, true, true))
229
-
.add(new KnownError(INVALID_SELECTOR_ERROR, "invalid selector", 400, InvalidSelectorException.class, true, true))
230
-
.add(new KnownError(INVALID_XPATH_SELECTOR, "invalid selector", 400, InvalidSelectorException.class, false, false))
231
-
.add(new KnownError(INVALID_XPATH_SELECTOR_RETURN_TYPER, "invalid selector", 400, InvalidSelectorException.class, false, true))
232
-
.add(new KnownError(JAVASCRIPT_ERROR, "javascript error", 500, JavascriptException.class, true, true))
233
-
.add(new KnownError(METHOD_NOT_ALLOWED, "unknown method", 405, UnsupportedCommandException.class, false, true))
234
-
.add(new KnownError(METHOD_NOT_ALLOWED, "unsupported operation", 500, UnsupportedCommandException.class, false, true))
235
-
.add(new KnownError(MOVE_TARGET_OUT_OF_BOUNDS, "move target out of bounds", 500, MoveTargetOutOfBoundsException.class, true, true))
236
-
.add(new KnownError(NO_ALERT_PRESENT, "no such alert", 404, NoAlertPresentException.class, true, true))
237
-
.add(new KnownError(NO_SUCH_COOKIE, "no such cookie", 404, NoSuchCookieException.class, true, true))
238
-
.add(new KnownError(NO_SUCH_ELEMENT, "no such element", 404, NoSuchElementException.class, true, true))
239
-
.add(new KnownError(NO_SUCH_FRAME, "no such frame", 404, NoSuchFrameException.class, true, true))
240
-
.add(new KnownError(NO_SUCH_SESSION, "invalid session id", 404, NoSuchSessionException.class, true, true))
241
-
.add(new KnownError(NO_SUCH_SHADOW_ROOT, "no such shadow root", 404, NoSuchShadowRootException.class, true, true))
242
-
.add(new KnownError(NO_SUCH_WINDOW, "no such window", 404, NoSuchWindowException.class, true, true))
243
-
.add(new KnownError(SESSION_NOT_CREATED, "session not created", 500, SessionNotCreatedException.class ,true, true))
244
-
.add(new KnownError(STALE_ELEMENT_REFERENCE, "stale element reference", 404, StaleElementReferenceException.class, true, true))
245
-
.add(new KnownError(TIMEOUT, "timeout", 500, TimeoutException.class, true, true))
246
-
.add(new KnownError(XPATH_LOOKUP_ERROR, "invalid selector", 400, InvalidSelectorException.class, false, false))
247
-
.add(new KnownError(UNABLE_TO_CAPTURE_SCREEN, "unable to capture screen", 500, ScreenshotException.class, true, true))
248
-
.add(new KnownError(UNABLE_TO_SET_COOKIE, "unable to set cookie", 500, UnableToSetCookieException.class, true, true))
249
-
.add(new KnownError(UNEXPECTED_ALERT_PRESENT, "unexpected alert open", 500, UnhandledAlertException.class, true, true))
250
-
.add(new KnownError(UNHANDLED_ERROR, "unknown error", 500, WebDriverException.class, true, true))
251
-
.add(new KnownError(UNKNOWN_COMMAND, "unknown command", 404, UnsupportedCommandException.class, true, true))
252
-
253
-
.build();
254
-
255
-
static {{
256
-
// Validate uniqueness constraints.
257
-
//
258
-
// There should be only one canonical JSON Wire protocol code per exception
259
-
Map<Object, Set<KnownError>> matched = new HashMap<>();
260
-
for (KnownError knownError : KNOWN_ERRORS) {
261
-
matched.computeIfAbsent(knownError, key -> new HashSet<>()).add(knownError);
262
-
}
263
-
for (Set<KnownError> errors : matched.values()) {
264
-
if (errors.size() != 1) {
265
-
throw new RuntimeException("Duplicate canonical exceptions: " + errors);
266
-
}
267
-
}
268
-
269
-
// There should only be one canonical W3C code to JSON Wire Protocol code
270
-
// matched = new HashMap<>();
271
-
// for (KnownError error : KNOWN_ERRORS) {
272
-
// matched.computeIfAbsent(error.getW3cCode(), key -> new HashSet<>()).add(error);
273
-
// }
274
-
// for (Set<KnownError> errors : matched.values()) {
275
-
// if (errors.size() != 1) {
276
-
// throw new RuntimeException("Duplicate canonical w3c state codes: " + errors);
277
-
// }
278
-
// }
279
-
}}
280
-
281
277
private static class KnownError {
282
278
private final int jsonCode;
283
279
private final String w3cCode;
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4