Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(eventsub): enforce static error categories #5903

Merged
merged 5 commits into from
Feb 7, 2025

Conversation

Nerixyz
Copy link
Contributor

@Nerixyz Nerixyz commented Feb 5, 2025

Pop quiz: is there a requirement for the error_category passed to the error_code constructor (docs)?


Doesn't look like it. boost::system::error_category doesn't say anything either (maybe I missed something). Well, turns out, error_category instances are treated like singletons. So we shouldn't construct them at runtime. One additional constraint we'd like to enforce is that they're supposed to be constant initialized (without the implicit lock inserted by the compiler for statics). We can achieve both of these by constructing a single global instance of the category and by using std/boost::source_location.

Initially, I had some funky workarounds for not being able to pass strings through the code (first commit). However, I realized that the location in the file where an error was emitted from contains the same (if not more) information. This is also simpler, because it's encouraged by boost::system::error_code.

@pajlada
Copy link
Member

pajlada commented Feb 5, 2025

This type of error seems fine to me 👍

Missing required key (/home/pajlada/git/chatterino/chatterino2/lib/twitch-eventsub-ws/src/generated/payloads/channel-moderate-v2.cpp:228:53 in function 'boost::json::result_for<Vip, boost::json::value>::type chatterino::eventsub::lib::payload::channel_moderate::v2::tag_invoke(boost::json::try_value_to_tag<Vip>, const boost::json::value &)')

@pajlada
Copy link
Member

pajlada commented Feb 5, 2025

Since we use mostly generated code, we don't have to use the macro if it's causing issues

@pajlada pajlada enabled auto-merge (squash) February 7, 2025 15:19
@pajlada pajlada merged commit f37676f into Chatterino:master Feb 7, 2025
18 checks passed
@Nerixyz Nerixyz deleted the refactor/eventsub-errors branch February 7, 2025 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants