Skip to content

fix: prevent duplicate hub rules acceptance entries and handle errors #254

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sentry-autofix[bot]
Copy link

👋 Hi there! This PR was automatically generated by Autofix 🤖

This fix was triggered by dev-737.

Fixes INTERCHAT-PRODUCTION-1F3. The issue was that: handleHubRulesAccept attempts to create HubRulesAcceptance without checking for existing records, causing a unique constraint error on duplicate requests.

  • Replaced create with upsert to prevent duplicate entries in hubRulesAcceptance table.
  • Added error handling around the database operation to catch potential issues.
  • Added a check to prevent attempting to reply to an interaction that has already been replied to, avoiding errors.

If you have any questions or feedback for the Sentry team about this fix, please email autofix@sentry.io with the Run ID: 29894.

@dev-737 dev-737 requested a review from Copilot April 19, 2025 06:27
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

A bugfix PR to prevent duplicate hub rules acceptance entries and to improve error handling during interaction responses.

  • Replaced the direct create call with an upsert to prevent unique constraint errors.
  • Wrapped the database operation in a try‐catch block with updated error handling.
  • Added a check to avoid replying to an interaction that has already been replied to.

Comment on lines +285 to +301
if (!interaction.replied) {
await interaction.followUp({ embeds: [embed], components: [], flags: ['Ephemeral'] });
await this.redis.del(`${RedisKeys.RulesShown}:${interaction.user.id}:${hubId}`);
}
} catch (error) {
Logger.error('Error while accepting hub rules:', error);
// Don't attempt to reply if the interaction was already replied to
if (!interaction.replied) {
const locale = await fetchUserLocale(interaction.user.id);
await interaction.followUp({
content: t('errors.generalError', locale, {
emoji: getEmoji('x_icon', interaction.client)
}),
flags: ['Ephemeral']
});
}
}
Copy link
Preview

Copilot AI Apr 19, 2025

Choose a reason for hiding this comment

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

The repeated check for '!interaction.replied' in both the main execution path and the error handling block could lead to subtle logic issues if the interaction state changes unexpectedly. Consider consolidating this logic to ensure the interaction is only replied to once.

Suggested change
if (!interaction.replied) {
await interaction.followUp({ embeds: [embed], components: [], flags: ['Ephemeral'] });
await this.redis.del(`${RedisKeys.RulesShown}:${interaction.user.id}:${hubId}`);
}
} catch (error) {
Logger.error('Error while accepting hub rules:', error);
// Don't attempt to reply if the interaction was already replied to
if (!interaction.replied) {
const locale = await fetchUserLocale(interaction.user.id);
await interaction.followUp({
content: t('errors.generalError', locale, {
emoji: getEmoji('x_icon', interaction.client)
}),
flags: ['Ephemeral']
});
}
}
await this.safeReply(interaction, {
embeds: [embed],
components: [],
flags: ['Ephemeral'],
});
await this.redis.del(`${RedisKeys.RulesShown}:${interaction.user.id}:${hubId}`);
} catch (error) {
Logger.error('Error while accepting hub rules:', error);
// Don't attempt to reply if the interaction was already replied to
const locale = await fetchUserLocale(interaction.user.id);
await this.safeReply(interaction, {
content: t('errors.generalError', locale, {
emoji: getEmoji('x_icon', interaction.client),
}),
flags: ['Ephemeral'],
});

Copilot uses AI. Check for mistakes.

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.

0 participants