1
0
mirror of synced 2024-11-17 03:27:13 +01:00

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.step // Whether or not to take one step or execute the whole recipe
);
if (typeof response.result === "string") {
if (response.progress !== data.progress + data.recipeConfig.length) {
self.postMessage({
action: "bakeError",
data: {
error: response.result,
action: "bakeComplete",
data: Object.assign(response, {
id: data.id,
inputNum: data.inputNum,
bakeId: data.bakeId,
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) {
self.postMessage({
action: "bakeError",

View File

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

View File

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

View File

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

View File

@ -142,11 +142,18 @@ class WorkerWaiter {
switch (r.action) {
case "bakeComplete":
log.debug(`Bake ${inputNum} complete.`);
this.updateOutput(r.data, r.data.inputNum, r.data.bakeId);
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;
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.app.progress = r.data.progress;
this.workerFinished(currentWorker);
@ -190,9 +197,11 @@ class WorkerWaiter {
* @param {Object} data
* @param {number} inputNum
* @param {number} bakeId
* @param {number} progress
*/
updateOutput(data, inputNum, bakeId) {
updateOutput(data, inputNum, bakeId, progress) {
this.manager.output.updateOutputBakeId(bakeId, inputNum);
this.manager.output.updateOutputProgress(progress, inputNum);
this.manager.output.updateOutputValue(data, inputNum);
this.manager.output.updateOutputStatus("baked", inputNum);
// this.manager.recipe.updateBreakpointIndicator(this.app.progress);