Commit 0263d973 authored by Miranda Fluharty's avatar Miranda Fluharty Committed by Clement Ho

Prevent this from happening again

If worker doesn't receive headIssues and baseIssues,
send back an empty object

If store doesn't receive newIssues and resolvedIssues,
reject the code quality comparison promise and
display the "Failed to load code quality" error
parent a416bd9d
...@@ -96,9 +96,11 @@ export default class MergeRequestStore extends CEMergeRequestStore { ...@@ -96,9 +96,11 @@ export default class MergeRequestStore extends CEMergeRequestStore {
static doCodeClimateComparison(headIssues, baseIssues) { static doCodeClimateComparison(headIssues, baseIssues) {
// Do these comparisons in worker threads to avoid blocking the main thread // Do these comparisons in worker threads to avoid blocking the main thread
return new Promise(resolve => { return new Promise((resolve, reject) => {
const worker = new CodeQualityComparisonWorker(); const worker = new CodeQualityComparisonWorker();
worker.addEventListener('message', ({ data }) => resolve(data)); worker.addEventListener('message', ({ data }) =>
data.newIssues && data.resolvedIssues ? resolve(data) : reject(data),
);
worker.postMessage({ worker.postMessage({
headIssues, headIssues,
baseIssues, baseIssues,
......
...@@ -7,15 +7,22 @@ self.addEventListener('message', e => { ...@@ -7,15 +7,22 @@ self.addEventListener('message', e => {
const { data } = e; const { data } = e;
if (data === undefined) { if (data === undefined) {
return; return null;
}
const { headIssues, baseIssues } = data;
if (!headIssues || !baseIssues) {
// eslint-disable-next-line no-restricted-globals
return self.postMessage({});
} }
// eslint-disable-next-line no-restricted-globals // eslint-disable-next-line no-restricted-globals
self.postMessage({ self.postMessage({
newIssues: filterByKey(data.parsedHeadIssues, data.parsedBaseIssues, keyToFilterBy), newIssues: filterByKey(headIssues, baseIssues, keyToFilterBy),
resolvedIssues: filterByKey(data.parsedBaseIssues, data.parsedHeadIssues, keyToFilterBy), resolvedIssues: filterByKey(baseIssues, headIssues, keyToFilterBy),
}); });
// eslint-disable-next-line no-restricted-globals // eslint-disable-next-line no-restricted-globals
self.close(); return self.close();
}); });
---
title: Fix variable mismatch in code quality widget
merge_request: 14829
author:
type: fixed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment