Improve handling of errors.

Add parameter to some update functions for whether or not to set the output
This commit is contained in:
j433866 2019-05-10 13:47:48 +01:00
parent f5442c307a
commit 2c02900edf
3 changed files with 16 additions and 14 deletions

View file

@ -573,13 +573,13 @@ self.loadFiles = function(filesData) {
/**
* Adds an input to the input array
*
* @param {boolean} [changetab=false] - Whether or not to send a message to the main thread that the input has been created
* @param {boolean} [changetab=false] - Whether or not to change to the new input
* @param {string} type - Either "string" or "file"
* @param {Object} fileData - Contains information about the file to be added to the input
* @param {string} fileData.name
* @param {string} fileData.size
* @param {string} fileData.type
* @param {number} inputNum
* @param {number} inputNum - Defaults to auto-incrementing self.currentInputNum
*/
self.addInput = function(changeTab=false, type, fileData={name: "unknown", size: "unknown", type: "unknown"}, inputNum = self.currentInputNum++) {
self.numInputs++;

View file

@ -129,16 +129,16 @@ class OutputWaiter {
*
* @param {Object} data
* @param {number} inputNum
* @param {boolean} set
*/
updateOutputValue(data, inputNum) {
updateOutputValue(data, inputNum, set=true) {
if (!this.outputExists(inputNum)) {
this.addOutput(inputNum);
}
this.outputs[inputNum].data = data;
// set output here
this.set(inputNum);
if (set) this.set(inputNum);
}
/**
@ -147,11 +147,12 @@ class OutputWaiter {
*
* @param {string} statusMessage
* @param {number} inputNum
* @param {boolean} [set=true]
*/
updateOutputMessage(statusMessage, inputNum) {
updateOutputMessage(statusMessage, inputNum, set=true) {
if (!this.outputExists(inputNum)) return;
this.outputs[inputNum].statusMessage = statusMessage;
this.set(inputNum);
if (set) this.set(inputNum);
}
/**
@ -166,7 +167,9 @@ class OutputWaiter {
updateOutputError(error, inputNum, progress=0) {
if (!this.outputExists(inputNum)) return;
this.outputs[inputNum].error = error;
const errorString = error.displayStr || error.toString();
this.outputs[inputNum].error = errorString;
this.outputs[inputNum].progress = progress;
this.updateOutputStatus("error", inputNum);
}
@ -278,7 +281,6 @@ class OutputWaiter {
} else if (output.status === "error") {
// style the tab if it's being shown
// run app.handleError()
this.toggleLoader(false);
outputText.style.display = "block";
outputText.classList.remove("blur");

View file

@ -145,7 +145,7 @@ class WorkerWaiter {
if (r.data.error) {
this.app.handleError(r.data.error);
this.manager.output.updateOutputError(r.data.result, inputNum, r.data.progress);
this.manager.output.updateOutputError(r.data.error, inputNum, r.data.progress);
this.workerFinished(currentWorker);
} else {
this.updateOutput(r.data, r.data.inputNum, r.data.bakeId, r.data.progress);
@ -171,7 +171,7 @@ class WorkerWaiter {
break;
case "statusMessage":
// Status message should be done per output
this.manager.output.updateOutputMessage(r.data.message, r.data.inputNum);
this.manager.output.updateOutputMessage(r.data.message, r.data.inputNum, true);
break;
case "optionUpdate":
log.debug(`Setting ${r.data.option} to ${r.data.value}`);
@ -202,7 +202,7 @@ class WorkerWaiter {
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.updateOutputValue(data, inputNum, false);
this.manager.output.updateOutputStatus("baked", inputNum);
}
@ -321,8 +321,8 @@ class WorkerWaiter {
if (typeof nextInput.inputNum === "string") nextInput.inputNum = parseInt(nextInput.inputNum, 10);
log.debug(`Baking input ${nextInput.inputNum}.`);
this.manager.output.updateOutputMessage(`Baking input ${nextInput.inputNum}...`, nextInput.inputNum, false);
this.manager.output.updateOutputStatus("baking", nextInput.inputNum);
this.manager.output.updateOutputMessage(`Baking input ${nextInput.inputNum}...`, nextInput.inputNum);
this.chefWorkers[workerIdx].inputNum = nextInput.inputNum;
this.chefWorkers[workerIdx].active = true;
@ -403,8 +403,8 @@ class WorkerWaiter {
break;
}
}
this.manager.output.updateOutputMessage(`Input ${inputData.inputNum} has not been baked yet.`, inputData.inputNum, false);
this.manager.output.updateOutputStatus("pending", inputData.inputNum);
this.manager.output.updateOutputMessage(`Input ${inputData.inputNum} has not been baked yet.`, inputData.inputNum);
if (inputData.override) {