Skip to content

Commit d2b35ef

Browse files
Copilotalexr00
andcommitted
Fix: Ignore GraphQL permission error when quickly toggling reactions
When users quickly click on a reaction to add/remove it, a race condition can occur where the client tries to remove a reaction that the user doesn't have permission to remove. This results in a GraphQL error: "does not have the correct permissions to execute 'RemoveReaction'" This change silently ignores this specific error as it's expected behavior during rapid toggling of reactions. Fixes microsoft/vscode#69321 Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 03e39a2 commit d2b35ef

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/view/pullRequestCommentController.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -546,14 +546,25 @@ export class PullRequestCommentController extends CommentControllerBase implemen
546546
return;
547547
}
548548

549-
if (
550-
comment.reactions &&
551-
!comment.reactions.find(ret => ret.label === reaction.label && !!ret.authorHasReacted)
552-
) {
553-
// add reaction
554-
await this.pullRequestModel.addCommentReaction(comment.rawComment.graphNodeId, reaction);
555-
} else {
556-
await this.pullRequestModel.deleteCommentReaction(comment.rawComment.graphNodeId, reaction);
549+
try {
550+
if (
551+
comment.reactions &&
552+
!comment.reactions.find(ret => ret.label === reaction.label && !!ret.authorHasReacted)
553+
) {
554+
// add reaction
555+
await this.pullRequestModel.addCommentReaction(comment.rawComment.graphNodeId, reaction);
556+
} else {
557+
await this.pullRequestModel.deleteCommentReaction(comment.rawComment.graphNodeId, reaction);
558+
}
559+
} catch (e) {
560+
// Ignore permission errors when removing reactions due to race conditions
561+
// See: https://github.com/microsoft/vscode/issues/69321
562+
const errorMessage = (e as Error).message || String(e);
563+
if (errorMessage.includes('does not have the correct permissions to execute \'RemoveReaction\'')) {
564+
// Silently ignore this error - it occurs when quickly toggling reactions
565+
return;
566+
}
567+
throw e;
557568
}
558569
}
559570

src/view/reviewCommentController.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,14 @@ ${suggestionInformation.suggestionContent}
985985
);
986986
}
987987
} catch (e) {
988-
throw new Error(formatError(e));
988+
// Ignore permission errors when removing reactions due to race conditions
989+
// See: https://github.com/microsoft/vscode/issues/69321
990+
const errorMessage = formatError(e);
991+
if (errorMessage.includes('does not have the correct permissions to execute \'RemoveReaction\'')) {
992+
// Silently ignore this error - it occurs when quickly toggling reactions
993+
return;
994+
}
995+
throw new Error(errorMessage);
989996
}
990997
}
991998

0 commit comments

Comments
 (0)