Fix bug if fault occurs in precondition stage

This commit is contained in:
Zaid Abdulla committed 2020-02-09 21:39:45 -08:00
1 parent 603f5c79ac
commit 65bf6d7d6e
1 file changed
+12 -5
+12 -5
View File
@@ -229,8 +229,12 @@ function recordFault(
channels = sessionContext.channels; channels = sessionContext.channels;
} }
const channelKeys = Object.keys(channels);
if (!channelKeys.length)
throw new Error("Fault not associated with a channel!");
const faults = sessionContext.faults; const faults = sessionContext.faults;
for (const channel of Object.keys(channels)) { for (const channel of channelKeys) {
const provs = sessionContext.faults[channel] const provs = sessionContext.faults[channel]
? sessionContext.faults[channel].provisions ? sessionContext.faults[channel].provisions
: []; : [];
@@ -248,7 +252,7 @@ function recordFault(
++sessionContext.retries[channel]; ++sessionContext.retries[channel];
} else { } else {
sessionContext.retries[channel] = 0; sessionContext.retries[channel] = 0;
if (Object.keys(channels).length !== 1) faults[channel].retryNow = true; if (channelKeys.length !== 1) faults[channel].retryNow = true;
} }
if (channels[channel] === 0) faults[channel].precondition = true; if (channels[channel] === 0) faults[channel].precondition = true;
@@ -266,13 +270,13 @@ function recordFault(
} }
for (let i = 0; i < provisions.length; ++i) { for (let i = 0; i < provisions.length; ++i) {
for (const channel of Object.keys(channels)) { for (const channel of channelKeys) {
if ((channels[channel] >> i) & 1) if ((channels[channel] >> i) & 1)
faults[channel].provisions.push(provisions[i]); faults[channel].provisions.push(provisions[i]);
} }
} }
for (const channel of Object.keys(channels)) { for (const channel of channelKeys) {
const provs = faults[channel].provisions; const provs = faults[channel].provisions;
faults[channel].provisions = []; faults[channel].provisions = [];
appendProvisions(faults[channel].provisions, provs); appendProvisions(faults[channel].provisions, provs);
@@ -455,9 +459,12 @@ async function applyPresets(sessionContext: SessionContext): Promise<void> {
} }
filteredPresets.push(preset); filteredPresets.push(preset);
for (const k of extractParams(preset.precondition)) for (const k of extractParams(preset.precondition)) {
// Mark channel in case of fault during fetching precondition
sessionContext.channels[preset.channel] = 0;
if (typeof k === "string") parameters[k] = Path.parse(k); if (typeof k === "string") parameters[k] = Path.parse(k);
} }
}
const declarations = Object.values(parameters).map(v => ({ const declarations = Object.values(parameters).map(v => ({
path: v, path: v,