Error.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #pragma once
  8. #include <AK/DeprecatedString.h>
  9. #include <AK/JsonValue.h>
  10. namespace Web::WebDriver {
  11. // https://w3c.github.io/webdriver/#dfn-error-code
  12. enum class ErrorCode {
  13. ElementClickIntercepted,
  14. ElementNotInteractable,
  15. InsecureCertificate,
  16. InvalidArgument,
  17. InvalidCookieDomain,
  18. InvalidElementState,
  19. InvalidSelector,
  20. InvalidSessionId,
  21. JavascriptError,
  22. MoveTargetOutOfBounds,
  23. NoSuchAlert,
  24. NoSuchCookie,
  25. NoSuchElement,
  26. NoSuchFrame,
  27. NoSuchWindow,
  28. NoSuchShadowRoot,
  29. ScriptTimeoutError,
  30. SessionNotCreated,
  31. StaleElementReference,
  32. DetachedShadowRoot,
  33. Timeout,
  34. UnableToSetCookie,
  35. UnableToCaptureScreen,
  36. UnexpectedAlertOpen,
  37. UnknownCommand,
  38. UnknownError,
  39. UnknownMethod,
  40. UnsupportedOperation,
  41. // Non-standard error codes:
  42. OutOfMemory,
  43. };
  44. // https://w3c.github.io/webdriver/#errors
  45. struct Error {
  46. unsigned http_status;
  47. DeprecatedString error;
  48. DeprecatedString message;
  49. Optional<JsonValue> data;
  50. static Error from_code(ErrorCode, DeprecatedString message, Optional<JsonValue> data = {});
  51. Error(unsigned http_status, DeprecatedString error, DeprecatedString message, Optional<JsonValue> data);
  52. Error(AK::Error const&);
  53. };
  54. }
  55. template<>
  56. struct AK::Formatter<Web::WebDriver::Error> : Formatter<StringView> {
  57. ErrorOr<void> format(FormatBuilder& builder, Web::WebDriver::Error const& error)
  58. {
  59. return Formatter<StringView>::format(builder, DeprecatedString::formatted("Error {}, {}: {}", error.http_status, error.error, error.message));
  60. }
  61. };