Skip to content

Discord bot panics when the Twitch user lookup fails during a live announcement #720

Description

@emircan-sahin

Describe the bug
When a streamer goes live, the Discord bot looks up their Twitch profile for the embed thumbnail. If that Helix call fails (503, timeout, 429), the error is ignored and userInfo.ProfileImageURL is read from a nil pointer, which panics and kills the process:

annoContent := s.GetStreamAnnoContent(ctx, service, guildId, streamerData.UserID)
formattedString := helper.FormatContent(annoContent, streamerData)
userInfo, err := s.twitchService.GetUserInfoByLoginName(streamerData.UserLogin)
if err != nil {
// TODO
}
dS.ChannelMessageSendComplex(gs.DiscordChannelID, &discordgo.MessageSend{Content: formattedString, Embeds: []*discordgo.MessageEmbed{
{
Title: fmt.Sprintf("%s - Twitch", streamerData.UserName),
Description: streamerData.Title,
URL: fmt.Sprintf("https://twitch.tv/%s", streamerData.UserLogin),
Thumbnail: &discordgo.MessageEmbedThumbnail{URL: userInfo.ProfileImageURL},
},

To Reproduce
Make GetUserInfoByLoginName return an error during handleAnnouncement (reproduced with a fake TwitchService): invalid memory address or nil pointer dereference.

Expected behavior
The announcement is sent without a thumbnail (or skipped and retried), and the bot keeps running.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions