Avoid 'comment thread without side' error
We have seen this often in flaky tests. I could not easily find the
root cause for this error, and I think finding it might take quite
some time. So I am opting for the easy fix and just logging a warning
instead of throwing an error when encountering a comment thread
without the `comment-side` attribute set. Not great, but certainly
better than suffering from flaky tests.
Change-Id: I0a94509e36b14a1c59a617e04816687793027265
diff --git a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.ts b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.ts
index ae3e016..d8d6115 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.ts
@@ -67,9 +67,12 @@
const FULL_CONTEXT = -1;
const LIMITED_CONTEXT = 10;
-function getSide(threadEl: GrCommentThread): Side {
+function getSide(threadEl: GrCommentThread): Side | undefined {
const sideAtt = threadEl.getAttribute('comment-side');
- if (!sideAtt) throw Error('comment thread without side');
+ if (!sideAtt) {
+ console.warn('comment thread without side');
+ return undefined;
+ }
if (sideAtt !== 'left' && sideAtt !== 'right')
throw Error(`unexpected value for side: ${sideAtt}`);
return sideAtt as Side;
@@ -387,7 +390,7 @@
threadEl: GrCommentThread
): CommentRangeLayer | undefined {
const side = getSide(threadEl);
-
+ if (!side) return undefined;
const rangeAtt = threadEl.getAttribute('range');
if (!rangeAtt) return undefined;
const range = JSON.parse(rangeAtt) as CommentRange;
@@ -433,6 +436,7 @@
for (const threadEl of threadEls) {
const side = getSide(threadEl);
+ if (!side) continue;
const lineNum = threadEl.getAttribute('line-num') || FILE;
const commentRange = threadEl.range || {};
keyLocations[side][lineNum] = true;
@@ -893,6 +897,7 @@
for (const threadEl of addedThreadEls) {
const lineNumString = threadEl.getAttribute('line-num') || 'FILE';
const commentSide = getSide(threadEl);
+ if (!commentSide) continue;
const lineEl = this.$.diffBuilder.getLineElByNumber(
lineNumString,
commentSide