From 2c02900edf15ebcf4f23051d159837bbc25b512f Mon Sep 17 00:00:00 2001 From: j433866 Date: Fri, 10 May 2019 13:47:48 +0100 Subject: [PATCH] Improve handling of errors. Add parameter to some update functions for whether or not to set the output --- src/web/InputWorker.mjs | 4 ++-- src/web/OutputWaiter.mjs | 16 +++++++++------- src/web/WorkerWaiter.mjs | 10 +++++----- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/web/InputWorker.mjs b/src/web/InputWorker.mjs index d0c68f12..cbe7f32c 100644 --- a/src/web/InputWorker.mjs +++ b/src/web/InputWorker.mjs @@ -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++; diff --git a/src/web/OutputWaiter.mjs b/src/web/OutputWaiter.mjs index 074ef376..b6682637 100755 --- a/src/web/OutputWaiter.mjs +++ b/src/web/OutputWaiter.mjs @@ -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"); diff --git a/src/web/WorkerWaiter.mjs b/src/web/WorkerWaiter.mjs index d35279bb..711014aa 100644 --- a/src/web/WorkerWaiter.mjs +++ b/src/web/WorkerWaiter.mjs @@ -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) {