Serenity Operating System
1/*
2 * Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
3 * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#pragma once
9
10#include <AK/DeprecatedString.h>
11#include <AK/JsonValue.h>
12
13namespace Web::WebDriver {
14
15// https://w3c.github.io/webdriver/#dfn-error-code
16enum class ErrorCode {
17 ElementClickIntercepted,
18 ElementNotInteractable,
19 InsecureCertificate,
20 InvalidArgument,
21 InvalidCookieDomain,
22 InvalidElementState,
23 InvalidSelector,
24 InvalidSessionId,
25 JavascriptError,
26 MoveTargetOutOfBounds,
27 NoSuchAlert,
28 NoSuchCookie,
29 NoSuchElement,
30 NoSuchFrame,
31 NoSuchWindow,
32 NoSuchShadowRoot,
33 ScriptTimeoutError,
34 SessionNotCreated,
35 StaleElementReference,
36 DetachedShadowRoot,
37 Timeout,
38 UnableToSetCookie,
39 UnableToCaptureScreen,
40 UnexpectedAlertOpen,
41 UnknownCommand,
42 UnknownError,
43 UnknownMethod,
44 UnsupportedOperation,
45
46 // Non-standard error codes:
47 OutOfMemory,
48};
49
50// https://w3c.github.io/webdriver/#errors
51struct Error {
52 unsigned http_status;
53 DeprecatedString error;
54 DeprecatedString message;
55 Optional<JsonValue> data;
56
57 static Error from_code(ErrorCode, DeprecatedString message, Optional<JsonValue> data = {});
58
59 Error(unsigned http_status, DeprecatedString error, DeprecatedString message, Optional<JsonValue> data);
60 Error(AK::Error const&);
61};
62
63}
64
65template<>
66struct AK::Formatter<Web::WebDriver::Error> : Formatter<StringView> {
67 ErrorOr<void> format(FormatBuilder& builder, Web::WebDriver::Error const& error)
68 {
69 return Formatter<StringView>::format(builder, DeprecatedString::formatted("Error {}, {}: {}", error.http_status, error.error, error.message));
70 }
71};