This repository was archived by the owner on Aug 7, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
fix: prevent duplicate hub rules acceptance entries and handle errors #254
Draft
seer-by-sentry
wants to merge
1
commit into
main
Choose a base branch
from
autofix/fix-duplicate-rules-acceptance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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'] | ||
}); | ||
} | ||
} |
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.
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.
Positive FeedbackNegative Feedback
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
None yet
0 participants
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
👋 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.