🚧 feat: Add empty contract list handling in boost admin#1928
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds handling for the scenario where the contract list is empty after filtering in the boost admin functionality. However, the implementation contains logic issues that prevent it from functioning correctly.
- Adds a check for empty contract fields before returning the final embed
- Attempts to handle the case where no contracts are available to display
| if len(Contracts) == 0 { | ||
| embed := &discordgo.MessageSend{ | ||
| Embeds: []*discordgo.MessageEmbed{{ | ||
| Type: discordgo.EmbedTypeRich, | ||
| Title: "Contract List", | ||
| Description: "No contracts available", | ||
| Color: getRandomColor(), | ||
| Fields: field, | ||
| }}, | ||
| } | ||
| return "", embed, nil | ||
| } |
There was a problem hiding this comment.
The nested condition checking len(Contracts) == 0 is unreachable because this function already returns early (lines 212-224) when there are no contracts. If execution reaches line 281, len(Contracts) is guaranteed to be greater than 0.
The real issue to handle here is when len(field) == 0 due to guild filtering (all contracts were filtered out by the guildID check at lines 261-264). In that case, the embed should indicate "No contracts for this guild" rather than "No contracts available".
| if len(Contracts) == 0 { | |
| embed := &discordgo.MessageSend{ | |
| Embeds: []*discordgo.MessageEmbed{{ | |
| Type: discordgo.EmbedTypeRich, | |
| Title: "Contract List", | |
| Description: "No contracts available", | |
| Color: getRandomColor(), | |
| Fields: field, | |
| }}, | |
| } | |
| return "", embed, nil | |
| } | |
| embed := &discordgo.MessageSend{ | |
| Embeds: []*discordgo.MessageEmbed{{ | |
| Type: discordgo.EmbedTypeRich, | |
| Title: "Contract List", | |
| Description: "No contracts for this guild", | |
| Color: getRandomColor(), | |
| Fields: field, | |
| }}, | |
| } | |
| return "", embed, nil |
| Title: "Contract List", | ||
| Description: "No contracts available", | ||
| Color: getRandomColor(), | ||
| Fields: field, |
There was a problem hiding this comment.
Setting Fields: field when field is guaranteed to be empty (since we're inside a len(field) == 0 check) is unnecessary. You can omit this field assignment or explicitly set it to nil.
| Fields: field, |
No description provided.