Check replacement in suggestion
It can happen that suggestion is returned without any replacement.
In this case, we ignore suggestion and don't save it to comment state.
Before this change it caused Error 400 and broke saving a draft.
Release-Notes: skip
Google-Bug-Id: b/328015414
Change-Id: I85cbc197aacaba4d9a47d1eed4849c04776c08b4
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 ce9c1c2..9640576 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -1182,7 +1182,7 @@
hasNewRange: suggestionResponse.suggestions?.[0]?.newRange !== undefined,
});
const suggestion = suggestionResponse.suggestions?.[0];
- if (!suggestion) return;
+ if (!suggestion?.replacement) return;
this.generatedSuggestion = suggestion;
}
@@ -1232,7 +1232,9 @@
numSuggestions: suggestionResponse.fix_suggestions.length,
});
const suggestion = suggestionResponse.fix_suggestions?.[0];
- if (!suggestion) return;
+ if (!suggestion?.replacements || suggestion.replacements.length === 0) {
+ return;
+ }
this.generatedFixSuggestion = suggestion;
this.autoSaveTrigger$.next();
}