Merge "Fix gr-comment-thread_test errors"
diff --git a/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread_test.js b/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread_test.js
index a25a4c7..f451527 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread_test.js
+++ b/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread_test.js
@@ -34,6 +34,9 @@
       });
 
       element = basicFixture.instantiate();
+      element.patchNum = '3';
+      element.changeNum = '1';
+      flushAsynchronousOperations();
     });
 
     test('comments are sorted correctly', () => {
@@ -248,6 +251,8 @@
       deleteDiffDraft() { return Promise.resolve({ok: true}); },
     });
     element = withCommentFixture.instantiate();
+    element.patchNum = '1';
+    element.changeNum = '1';
     element.comments = [{
       author: {
         name: 'Mr. Peanutbutter',
@@ -310,6 +315,7 @@
         email: 'tenn1sballchaser@aol.com',
       },
       id: 'baf0414d_60047215',
+      path: 'test',
       line: 5,
       message: 'is this a crossover episode!?\nIt might be!',
       updated: '2015-12-08 19:48:33.843000000',
@@ -495,6 +501,7 @@
       },
       id: 'baf0414d_60047215',
       line: 5,
+      path: 'test',
       message: 'is this a crossover episode!?',
       updated: '2015-12-08 19:48:33.843000000',
       __draft: true,
@@ -519,6 +526,7 @@
         email: 'tenn1sballchaser@aol.com',
       },
       id: 'baf0414d_60047215',
+      path: 'test',
       line: 5,
       message: 'is this a crossover episode!?',
       updated: '2015-12-08 19:48:31.843000000',
@@ -530,6 +538,7 @@
       },
       __draftID: '1',
       in_reply_to: 'baf0414d_60047215',
+      path: 'test',
       line: 5,
       message: 'yes',
       updated: '2015-12-08 19:48:32.843000000',
@@ -543,6 +552,7 @@
       },
       __draftID: '2',
       in_reply_to: 'baf0414d_60047215',
+      path: 'test',
       line: 5,
       message: 'no',
       updated: '2015-12-08 19:48:33.843000000',
@@ -823,6 +833,8 @@
       deleteDiffDraft() { return Promise.resolve({ok: true}); },
     });
     element = withCommentFixture.instantiate();
+    element.patchNum = '1';
+    element.changeNum = '1';
     element.comments = [{
       author: {
         name: 'Mr. Peanutbutter',
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
index 209b2c9..68e65bc 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -627,33 +627,34 @@
     const patchNum = this.comment.patch_set
       ? this.comment.patch_set
       : this._getPatchNum();
-    this.debounce(
-      'store',
-      () => {
-        const message = this._messageText;
-        if (!this.comment?.path || this.comment.line === undefined)
-          throw new Error('missing path or line in comment');
-        if (this.changeNum === undefined) {
-          throw new Error('undefined changeNum');
-        }
-        const commentLocation: StorageLocation = {
-          changeNum: this.changeNum,
-          patchNum,
-          path: this.comment.path,
-          line: this.comment.line,
-          range: this.comment.range,
-        };
+    const {path, line, range} = this.comment;
+    if (path && line !== undefined) {
+      this.debounce(
+        'store',
+        () => {
+          const message = this._messageText;
+          if (this.changeNum === undefined) {
+            throw new Error('undefined changeNum');
+          }
+          const commentLocation: StorageLocation = {
+            changeNum: this.changeNum,
+            patchNum,
+            path,
+            line,
+            range,
+          };
 
-        if ((!this._messageText || !this._messageText.length) && oldValue) {
-          // If the draft has been modified to be empty, then erase the storage
-          // entry.
-          this.$.storage.eraseDraftComment(commentLocation);
-        } else {
-          this.$.storage.setDraftComment(commentLocation, message);
-        }
-      },
-      STORAGE_DEBOUNCE_INTERVAL
-    );
+          if ((!message || !message.length) && oldValue) {
+            // If the draft has been modified to be empty, then erase the storage
+            // entry.
+            this.$.storage.eraseDraftComment(commentLocation);
+          } else {
+            this.$.storage.setDraftComment(commentLocation, message);
+          }
+        },
+        STORAGE_DEBOUNCE_INTERVAL
+      );
+    }
   }
 
   _handleAnchorClick(e: Event) {
@@ -675,8 +676,7 @@
 
   _handleEdit(e: Event) {
     e.preventDefault();
-    if (!this.comment?.message) throw new Error('message undefined');
-    this._messageText = this.comment.message;
+    if (this.comment?.message) this._messageText = this.comment.message;
     this.editing = true;
     this.reporting.recordDraftInteraction();
   }
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.js b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.js
index a9a1d32..6cda593 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.js
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.js
@@ -316,6 +316,7 @@
       });
 
       test('create', () => {
+        element.patchNum = 1;
         element.comment = {};
         return element._handleSave(mockEvent).then(() => {
           assert.equal(element.shadowRoot.querySelector('gr-account-label').