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

Improved error messaging for Update Channel API #5429

Merged
merged 15 commits into from
Jun 9, 2024

Conversation

JakeRYW
Copy link
Contributor

@JakeRYW JakeRYW commented May 29, 2024

Adding appropriate error handling for the /settitle and /setgame commands. Handles trying to set the title/game in unauthorized channels, missing scope, rate limits, and title being too long by providing Failed to set title - Title is too long. error message.

Also removed the status variable declaration from the setTitle function as it was not used.

Fixes #5332

Comment on lines 35 to 40
if(title.size() > 140)
{
ctx.channel->addMessage(
makeSystemMessage("Unable to set title: Title must be 140 characters or fewer."));
return "";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be a client-side check. #5332 mentions that the response we get from Twitch's Helix API may include a message field which we can use to report back. Currently, we're not doing anything with the response in case of an error (see Helix.cpp).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nerixyz is correct - the reason we try using server-side errors wherever possible is to ensure compatibility with API changes (e.g. if Twitch changes their max title length to 120 or 160)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the client side check, and added error handling for both the settitle and setgame since they are both utilizing the Update Channel API.

@JakeRYW JakeRYW changed the title Add error message for channel titles exceeding 140 characters Add updated error handling for Update Channel API Jun 3, 2024
@JakeRYW JakeRYW requested review from Nerixyz and pajlada June 3, 2024 00:49
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/providers/twitch/api/Helix.hpp Outdated Show resolved Hide resolved
Copy link
Contributor

@Nerixyz Nerixyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, just a few things.

}
break;

case 409:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong. Shouldn't 409 forward the message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the Modify Channel Information docs, 409 for this endpoint will give a Too Many Requests response when trying to see the Branded Content flag too frequently, which wouldn't be hit by /settitle or /settgame of course but I just tried to handle all errors currently provided in the docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. I read Too Many Requests and thought it would be 429. Probably should say 409 Conflict in the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it looks like it's just a typo in the docs, I'll remove the 409, and leave it to just 429.


case Error::Unknown:
default: {
errorMessage += "An unknown error has occured.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should include the message - like "Failed to set title - An unknown error has occurred ({message})" (there's also a typo in occured → occurred, which is also present in the error handling of manageAutoModMessages and the comment for secondsSinceDisconnect).

Comment on lines 147 to 181
using Error = HelixUpdateChannelError;

switch(error)
{
case Error::UserMissingScope: {
errorMessage += "Missing required scope. "
"Re-login with your "
"account and try again.";
}
break;

case Error::UserNotAuthorized: {
errorMessage += "You must be the broadcaster "
"to set the game.";
}
break;

case Error::Ratelimited: {
errorMessage +=
"You are being ratelimited by Twitch. Try "
"again in a few seconds.";
}
break;

case Error::Forwarded: {
errorMessage += message;
}
break;

case Error::Unknown:
default: {
errorMessage += "An unknown error has occured.";
}
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost identical to the code above and should be refactored into a function (in an anonymous namespace above chatterino::commands).

@JakeRYW JakeRYW requested a review from Nerixyz June 3, 2024 14:04
Copy link
Contributor

@Nerixyz Nerixyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, now you just need a changelog entry!

@JakeRYW JakeRYW requested a review from Nerixyz June 7, 2024 13:26
Copy link
Contributor

@Nerixyz Nerixyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already approved the changes (I'm not a collaborator, so my opinion doesn't matter). Changelog entry looks okay.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/providers/twitch/api/Helix.hpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

mocks/include/mocks/Helix.hpp Show resolved Hide resolved
src/providers/twitch/api/Helix.hpp Outdated Show resolved Hide resolved
Copy link
Member

@pajlada pajlada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! As a first-time contributor, you can now add yourself to the contributors list that's shown inside the About page in Chatterino.

If you want this, you can open a new PR where you modify the resources/contributors.txt file and add yourself to the list. Make sure to read the comments at the top for instructions.

@pajlada pajlada changed the title Add updated error handling for Update Channel API Improved error messaging for Update Channel API Jun 8, 2024
@pajlada pajlada enabled auto-merge (squash) June 8, 2024 09:51
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

mocks/include/mocks/Helix.hpp Show resolved Hide resolved
src/providers/twitch/api/Helix.hpp Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

std::function<void(NetworkResult)> successCallback,
HelixFailureCallback failureCallback),
(override));
MOCK_METHOD(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: invalid case style for function 'MOCK_METHOD' [readability-identifier-naming]

Suggested change
MOCK_METHOD(
mockMethod(

/// Error type for Helix::updateChannel
///
/// Used in the /settitle and /setgame commands
enum class HelixUpdateChannelError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: enum 'HelixUpdateChannelError' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]

enum class HelixUpdateChannelError {
           ^

@pajlada pajlada merged commit 25284fc into Chatterino:master Jun 9, 2024
17 checks passed
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.

No error handling on /settitle
3 participants