Improve handling of errors in operations.

Remove unused dependencies.
This commit is contained in:
j433866 2019-05-08 11:57:22 +01:00
parent 689d08416b
commit f72749304d
5 changed files with 38 additions and 42 deletions

View File

@ -102,37 +102,15 @@ async function bake(data) {
data.progress, // The current position in the recipe data.progress, // The current position in the recipe
data.step // Whether or not to take one step or execute the whole recipe data.step // Whether or not to take one step or execute the whole recipe
); );
if (typeof response.result === "string") { self.postMessage({
if (response.progress !== data.progress + data.recipeConfig.length) { action: "bakeComplete",
self.postMessage({ data: Object.assign(response, {
action: "bakeError", id: data.id,
data: { inputNum: data.inputNum,
error: response.result, bakeId: data.bakeId,
id: data.id, progress: response.progress
inputNum: data.inputNum, })
progress: response.progress });
}
});
} else {
self.postMessage({
action: "bakeComplete",
data: Object.assign(response, {
id: data.id,
inputNum: data.inputNum,
bakeId: data.bakeId
})
});
}
} else {
self.postMessage({
action: "bakeComplete",
data: Object.assign(response, {
id: data.id,
inputNum: data.inputNum,
bakeId: data.bakeId
})
}, [response.result]);
}
} catch (err) { } catch (err) {
self.postMessage({ self.postMessage({
action: "bakeError", action: "bakeError",

View File

@ -5,7 +5,6 @@
*/ */
import Utils from "../core/Utils"; import Utils from "../core/Utils";
import {toBase64} from "../core/lib/Base64";
/** /**

View File

@ -7,7 +7,6 @@
*/ */
import Utils from "../core/Utils"; import Utils from "../core/Utils";
import {toBase64} from "../core/lib/Base64";
self.maxWorkers = 4; self.maxWorkers = 4;
self.maxTabs = 1; self.maxTabs = 1;

View File

@ -172,7 +172,6 @@ class OutputWaiter {
if (status !== "error") { if (status !== "error") {
delete this.outputs[inputNum].error; delete this.outputs[inputNum].error;
delete this.outputs[inputNum].progress;
} }
this.set(inputNum); this.set(inputNum);
@ -189,6 +188,17 @@ class OutputWaiter {
this.outputs[inputNum].bakeId = bakeId; this.outputs[inputNum].bakeId = bakeId;
} }
/**
* Updates the stored progress value for the output in the output array
*
* @param {number} progress
* @param {number} inputNum
*/
updateOutputProgress(progress, inputNum) {
if (this.getOutput(inputNum) === -1) return;
this.outputs[inputNum].progress = progress;
}
/** /**
* Removes an output from the output array. * Removes an output from the output array.
* *
@ -240,7 +250,11 @@ class OutputWaiter {
this.manager.controls.hideStaleIndicator(); this.manager.controls.hideStaleIndicator();
} }
this.manager.recipe.updateBreakpointIndicator(false); if (output.progress !== undefined) {
this.manager.recipe.updateBreakpointIndicator(output.progress);
} else {
this.manager.recipe.updateBreakpointIndicator(false);
}
document.getElementById("show-file-overlay").style.display = "none"; document.getElementById("show-file-overlay").style.display = "none";
@ -263,8 +277,6 @@ class OutputWaiter {
outputText.value = output.error; outputText.value = output.error;
outputHtml.innerHTML = ""; outputHtml.innerHTML = "";
this.manager.recipe.updateBreakpointIndicator(output.progress);
} else if (output.status === "baked" || output.status === "inactive") { } else if (output.status === "baked" || output.status === "inactive") {
this.displayTabInfo(inputNum); this.displayTabInfo(inputNum);
this.toggleLoader(false); this.toggleLoader(false);
@ -1122,7 +1134,6 @@ class OutputWaiter {
} }
/** /**
* Handler for copy click events. * Handler for copy click events.
* Copies the output to the clipboard * Copies the output to the clipboard

View File

@ -142,11 +142,18 @@ class WorkerWaiter {
switch (r.action) { switch (r.action) {
case "bakeComplete": case "bakeComplete":
log.debug(`Bake ${inputNum} complete.`); log.debug(`Bake ${inputNum} complete.`);
this.updateOutput(r.data, r.data.inputNum, r.data.bakeId);
this.workerFinished(currentWorker); if (r.data.error) {
this.app.handleError(r.data.error);
this.manager.output.updateOutputError(r.data.result, inputNum, r.data.progress);
this.workerFinished(currentWorker);
} else {
this.updateOutput(r.data, r.data.inputNum, r.data.bakeId, r.data.progress);
this.workerFinished(currentWorker);
}
break; break;
case "bakeError": case "bakeError":
if (!r.data.hasOwnProperty("progress")) this.app.handleError(r.data.error); this.app.handleError(r.data.error);
this.manager.output.updateOutputError(r.data.error, inputNum, r.data.progress); this.manager.output.updateOutputError(r.data.error, inputNum, r.data.progress);
this.app.progress = r.data.progress; this.app.progress = r.data.progress;
this.workerFinished(currentWorker); this.workerFinished(currentWorker);
@ -190,9 +197,11 @@ class WorkerWaiter {
* @param {Object} data * @param {Object} data
* @param {number} inputNum * @param {number} inputNum
* @param {number} bakeId * @param {number} bakeId
* @param {number} progress
*/ */
updateOutput(data, inputNum, bakeId) { updateOutput(data, inputNum, bakeId, progress) {
this.manager.output.updateOutputBakeId(bakeId, inputNum); this.manager.output.updateOutputBakeId(bakeId, inputNum);
this.manager.output.updateOutputProgress(progress, inputNum);
this.manager.output.updateOutputValue(data, inputNum); this.manager.output.updateOutputValue(data, inputNum);
this.manager.output.updateOutputStatus("baked", inputNum); this.manager.output.updateOutputStatus("baked", inputNum);
// this.manager.recipe.updateBreakpointIndicator(this.app.progress); // this.manager.recipe.updateBreakpointIndicator(this.app.progress);