mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 17:08:31 +01:00
Improve handling of errors.
Add parameter to some update functions for whether or not to set the output
This commit is contained in:
parent
f5442c307a
commit
2c02900edf
3 changed files with 16 additions and 14 deletions
|
@ -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++;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue