refactor(eventsub): enforce static error categories (#5903)

This commit is contained in:
nerix
2025-02-07 16:37:53 +01:00
committed by GitHub
parent 9260e72a0b
commit f37676fe1c
20 changed files with 374 additions and 1049 deletions
@@ -1,6 +1,6 @@
// WARNING: This file is automatically generated. Any changes will be lost.
#include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep
#include "twitch-eventsub-ws/errors.hpp"
#include "twitch-eventsub-ws/detail/errors.hpp"
#include "twitch-eventsub-ws/payloads/channel-ban-v1.hpp"
#include <boost/json.hpp>
@@ -12,20 +12,14 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
{
if (!jvRoot.is_object())
{
static const error::ApplicationErrorCategory errorMustBeObject{
"Event must be an object"};
return boost::system::error_code{129, errorMustBeObject};
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
}
const auto &root = jvRoot.get_object();
const auto *jvbroadcasterUserID = root.if_contains("broadcaster_user_id");
if (jvbroadcasterUserID == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_broadcasterUserID{
"Missing required key broadcaster_user_id"};
return boost::system::error_code{129,
error_missing_field_broadcasterUserID};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto broadcasterUserID =
@@ -40,11 +34,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
root.if_contains("broadcaster_user_login");
if (jvbroadcasterUserLogin == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_broadcasterUserLogin{
"Missing required key broadcaster_user_login"};
return boost::system::error_code{
129, error_missing_field_broadcasterUserLogin};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto broadcasterUserLogin =
@@ -59,11 +49,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
root.if_contains("broadcaster_user_name");
if (jvbroadcasterUserName == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_broadcasterUserName{
"Missing required key broadcaster_user_name"};
return boost::system::error_code{
129, error_missing_field_broadcasterUserName};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto broadcasterUserName =
@@ -77,11 +63,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
const auto *jvmoderatorUserID = root.if_contains("moderator_user_id");
if (jvmoderatorUserID == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_moderatorUserID{
"Missing required key moderator_user_id"};
return boost::system::error_code{129,
error_missing_field_moderatorUserID};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto moderatorUserID =
@@ -95,11 +77,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
const auto *jvmoderatorUserLogin = root.if_contains("moderator_user_login");
if (jvmoderatorUserLogin == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_moderatorUserLogin{
"Missing required key moderator_user_login"};
return boost::system::error_code{
129, error_missing_field_moderatorUserLogin};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto moderatorUserLogin =
@@ -113,11 +91,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
const auto *jvmoderatorUserName = root.if_contains("moderator_user_name");
if (jvmoderatorUserName == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_moderatorUserName{
"Missing required key moderator_user_name"};
return boost::system::error_code{129,
error_missing_field_moderatorUserName};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto moderatorUserName =
@@ -131,9 +105,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
const auto *jvuserID = root.if_contains("user_id");
if (jvuserID == nullptr)
{
static const error::ApplicationErrorCategory error_missing_field_userID{
"Missing required key user_id"};
return boost::system::error_code{129, error_missing_field_userID};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto userID = boost::json::try_value_to<std::string>(*jvuserID);
@@ -146,9 +118,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
const auto *jvuserLogin = root.if_contains("user_login");
if (jvuserLogin == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_userLogin{"Missing required key user_login"};
return boost::system::error_code{129, error_missing_field_userLogin};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto userLogin = boost::json::try_value_to<std::string>(*jvuserLogin);
@@ -161,9 +131,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
const auto *jvuserName = root.if_contains("user_name");
if (jvuserName == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_userName{"Missing required key user_name"};
return boost::system::error_code{129, error_missing_field_userName};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto userName = boost::json::try_value_to<std::string>(*jvuserName);
@@ -176,9 +144,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
const auto *jvreason = root.if_contains("reason");
if (jvreason == nullptr)
{
static const error::ApplicationErrorCategory error_missing_field_reason{
"Missing required key reason"};
return boost::system::error_code{129, error_missing_field_reason};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto reason = boost::json::try_value_to<std::string>(*jvreason);
@@ -191,10 +157,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
const auto *jvisPermanent = root.if_contains("is_permanent");
if (jvisPermanent == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_isPermanent{
"Missing required key is_permanent"};
return boost::system::error_code{129, error_missing_field_isPermanent};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto isPermanent = boost::json::try_value_to<bool>(*jvisPermanent);
@@ -207,9 +170,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
const auto *jvbannedAt = root.if_contains("banned_at");
if (jvbannedAt == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_bannedAt{"Missing required key banned_at"};
return boost::system::error_code{129, error_missing_field_bannedAt};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto bannedAt =
@@ -258,19 +219,14 @@ boost::json::result_for<Payload, boost::json::value>::type tag_invoke(
{
if (!jvRoot.is_object())
{
static const error::ApplicationErrorCategory errorMustBeObject{
"Payload must be an object"};
return boost::system::error_code{129, errorMustBeObject};
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
}
const auto &root = jvRoot.get_object();
const auto *jvsubscription = root.if_contains("subscription");
if (jvsubscription == nullptr)
{
static const error::ApplicationErrorCategory
error_missing_field_subscription{
"Missing required key subscription"};
return boost::system::error_code{129, error_missing_field_subscription};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto subscription =
@@ -284,9 +240,7 @@ boost::json::result_for<Payload, boost::json::value>::type tag_invoke(
const auto *jvevent = root.if_contains("event");
if (jvevent == nullptr)
{
static const error::ApplicationErrorCategory error_missing_field_event{
"Missing required key event"};
return boost::system::error_code{129, error_missing_field_event};
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto event = boost::json::try_value_to<Event>(*jvevent);