-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
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'] | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
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.
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.
👋 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 createHubRulesAcceptance
without checking for existing records, causing a unique constraint error on duplicate requests.create
withupsert
to prevent duplicate entries inhubRulesAcceptance
table.If you have any questions or feedback for the Sentry team about this fix, please email autofix@sentry.io with the Run ID: 29894.